CS FundamentalsVery hardGATE CS · Amazon/Microsoft SDE MCQ

Table Bill(id, cust, region, amt) rows: (1, 'Kavi', 'E', 300), (2, 'Lata', 'W', NULL), (3, 'Kavi', 'E', 450), (4, 'Mona', 'W', 300), (5, 'Nair', NULL, 200), (6, 'Lata', 'W', 450), (7, 'Mona', 'E', NULL). What values does the second column show for ids 5 and 1? SELECT id, LAST_VALUE(amt) OVER (ORDER BY amt) FROM Bill WHERE amt IS NOT NULL;

  1. A. 450 and 450
  2. B. 200 and 450
  3. C. 200 and 300
  4. D. 450 and 300

Correct answer: C. 200 and 300

The default frame ends at the current row and its peers, so LAST_VALUE returns the current row's own peer-group value, not the partition's last: 200 for bill 5 and 300 for bill 1. Getting 450 needs ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING.

More DBMS and SQL questions

Exams that ask this topic