What do LAG and LEAD do?
Model answer
LAG returns a value from a previous row and LEAD from a following row within the partition order. They are used to compare a row to the previous one, such as day-over-day change.
Learn this topic
Window Functions: ROW_NUMBER, RANK and Running Totals in the course SQL for Beginners: Learn Databases Step by Step.
Sign in to add your own answer.
More questions
- What is a window function and how is it different from GROUP BY?
- What is the difference between ROW_NUMBER, RANK and DENSE_RANK?
- What do PARTITION BY and ORDER BY do inside OVER?
- How do you calculate a running total?
- How do you find consecutive days (gaps and islands)?
- What does NTILE do and where is it used?