5 questions to test your understanding
You want to compute month-over-month revenue change for each row in a sales table ordered by month. Which approach is correct?
A query uses LAST_VALUE(price) OVER (PARTITION BY product ORDER BY sale_date). What does this return on each row with the default window frame?
When a partition boundary is crossed, LAG returns NULL (or the specified default) rather than looking into the previous partition.
LEAD and LAG are equivalent to window-aggregate functions like SUM OVER — they compute a value derived from most rows in the window frame.
Why did SQL need LAG and LEAD at all? What was the alternative before window functions, and what problem does the new approach solve?