CS FundamentalsHardGATE 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). For id 4, what is the second column? SELECT id, FIRST_VALUE(id) OVER (PARTITION BY region ORDER BY amt DESC) FROM Bill WHERE amt IS NOT NULL;

  1. A. 4
  2. B. 3
  3. C. 6
  4. D. 1

Correct answer: C. 6

Bill 4 is in region W, whose non-NULL rows are 6 (450) and 4 (300). Ordered by amt descending, the first is bill 6. Bill 3 is the first in region E, not W.

More DBMS and SQL questions

Exams that ask this topic