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). What values does this query show for ids 1 and 4? SELECT id, SUM(amt) OVER (ORDER BY amt) AS run FROM Bill WHERE amt IS NOT NULL;

  1. A. 500 and 800 (in some order)
  2. B. 800 and 800
  3. C. 300 and 600
  4. D. 200 and 500

Correct answer: B. 800 and 800

With ORDER BY and no frame clause the default frame is RANGE ... CURRENT ROW, which includes all peers. Ids 1 and 4 both have amt 300, so both get 200 + 300 + 300 = 800; 500 would need a ROWS frame.

More DBMS and SQL questions

Exams that ask this topic