Inter-Row Functions Usage

The inter-row functions LAG and LEAD enable access to previous values or subsequent values in a data series.

These functions provide access to more than one row of a table or partition simultaneously without a self join. The LAG function provides access to a row at a given physical offset prior to the CURRENT ROW in the table or partition. The LEAD function provides access to a row at a given physical offset after the CURRENT ROW in the table or partition. Use the LAG and LEAD functions to create queries such as “What was the stock price two intervals before the current row,” and “What was the stock price one interval after the current row.”

Inter-row functions require an OVER (ORDER_BY) clause.