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;
- A. (1, 300), (3, 300), (6, 300)
- B. (1, 100), (3, NULL), (6, 300)
- C. (1, 100), (3, NULL), (6, NULL)
- 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
- A file has 120,000 records of 150 bytes, stored unspanned in 4096-byte blocks and ordered on key K. A primary (sparse) index on K has one…
- Employee(eid, name) has a recursive one-to-many relationship 'manages' (a manager manages many employees; each employee has at most one…
- In logical query processing order, which clause of a SELECT statement is evaluated LAST?
- R(A, B, C, D, E, F) has FDs C → AD, EF → C, B → A, AD → E. Each option is a relation schema obtained by projecting R, with the…
- Table Product(pid, cat, price) rows: (1, 'X', 10), (2, 'X', 20), (3, 'Y', 20), (4, NULL, 30), (5, 'Y', NULL), (6, 'Z', 5). What does this…
- A B+ tree has at most 21 children per internal node and at most 20 keys per leaf. A non-root internal node must have at least ⌈21/2⌉…