CS FundamentalsHardProduct placement · SQL round

Table Sale(id, rep, region, amt) rows: (1, 'Ira', 'N', 100), (2, 'Jai', 'S', 250), (3, 'Ira', 'S', NULL), (4, 'Kim', 'N', 300), (5, 'Jai', 'N', 150), (6, 'Ira', 'N', 200), (7, 'Lal', NULL, 120). What does this query return?

Table Sale(id, rep, region, amt) rows: (1, 'Ira', 'N', 100), (2, 'Jai', 'S', 250), (3, 'Ira', 'S', NULL), (4, 'Kim', 'N', 300), (5, 'Jai', 'N', 150), (6, 'Ira', 'N', 200), (7, 'Lal', NULL, 120). What does this query return?
SELECT id, SUM(amt) OVER (PARTITION BY rep ORDER BY id) AS run
FROM Sale
WHERE rep = 'Ira'
ORDER BY id;
  1. A. (1, 300), (3, 300), (6, 300)
  2. B. (1, 100), (3, NULL), (6, 300)
  3. C. (1, 100), (3, NULL), (6, NULL)
  4. D. (1, 100), (3, 100), (6, 300)

Correct answer: D. (1, 100), (3, 100), (6, 300)

A running SUM skips NULLs rather than becoming NULL: after id 3 the total is still 100, and id 6 adds 200 to make 300.

More DBMS and SQL questions

Exams that ask this topic