LAG and LEAD
LAG and LEAD access values from other rows.
LAG(column) - previous row's value LEAD(column) - next row's value
Compare to previous:
Perfect for:
- Year-over-year comparisons
- Day-over-day changes
- Finding gaps in data
Check your understanding
Show each employee's salary and the next lower salary.
Examples run on the employees sample database. Open any of them in the playground to experiment.