Why does LAST_VALUE(x) OVER (ORDER BY ts) usually return the current row's value rather than the final value in the partition?
Correct answer
C. The default frame ends at the current row, so the last visible value is here
21 views
C. The default frame ends at the current row, so the last visible value is here
21 views
With an ORDER BY in the window, the default frame is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, so the last row visible to LAST_VALUE is the current one. Adding ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING makes it return the partition's final value. FIRST_VALUE escapes the surprise because its default frame already starts at the beginning of the partition.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is C? Ask here and get an explanation.