What does LAG(sales, 1, 0) OVER (PARTITION BY store ORDER BY month) return?
Correct answer
D. The previous month's sales within the same store, with 0 substituted for the first row of each partition
14 views
D. The previous month's sales within the same store, with 0 substituted for the first row of each partition
14 views
LAG looks backwards within the window frame, one row at a time here, and the third argument supplies a default instead of NULL for the first row of each partition. PARTITION BY restarts the window per store, so months never cross between stores. LEAD is the forward-looking counterpart, and SUM over an ordered frame gives the running total.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is D? Ask here and get an explanation.