Ordered analytic functions calculate an aggregate or non-aggregate value on a window of rows within a group of rows. The window of rows is defined by the Window Framing clause, also called the ROWS clause. Window sizes are based on the size specified in the ROWS clause. The group of rows is defined by the PARTITION BY clause of the Window function.
The LAG function accesses data from the row preceding the current row at a specified offset value in a window group, while the LEAD function returns data from the row following the current row. If the offset value is outside the scope of the window, the user-specified default value is returned.
The LAG and LEAD functions are used for OLAP and decision support queries.