CS FundamentalsHardGATE CS (PYQ pattern)
SL(r, q, amt): (N,Q1,10), (N,Q2,20), (S,Q1,5), (S,Q1,15), (S,Q2,NULL), (E,Q2,7). The query SELECT r, SUM(CASE WHEN q = 'Q1' THEN amt END) AS a, SUM(CASE WHEN q = 'Q2' THEN amt ELSE 0 END) AS b FROM SL GROUP BY r is run. How many result rows have a IS NULL, and what is the sum of the b column?
- A. 1 row; sum of b = 28
- B. 2 rows; sum of b = 27
- C. 1 row; sum of b = 27
- D. 0 rows; sum of b = 27
Correct answer: C. 1 row; sum of b = 27
Group E has no Q1 row, so CASE gives NULL for every row and SUM is NULL (1 row with a NULL). For b the ELSE 0 makes NULL amounts irrelevant: 20 + 0 + 7 = 27.
More DBMS and SQL questions
- Schedule: R1(A), W2(A), R3(B), R2(B), W3(C), W1(C), R4(D). How many different serial orders of T1, T2, T3, T4 are conflict-equivalent to it?
- Schedule (no commits yet): W1(A), R2(A), W2(B), R3(B), R4(C), W3(C), R5(D), W4(D). T1 now aborts. Which set of transactions must also be…
- Which of the following statements about the SQL standard isolation levels (locking-based implementation) are correct? I. READ COMMITTED…
- A log (immediate modification, redo-undo recovery, checkpoint lists active transactions) reads: <T1 start>, <T1,A,1,2>, <T2 start>…
- A B+ tree has 4096-byte nodes, 10-byte keys and 6-byte tree pointers. An internal node with n pointers carries n - 1 keys. A leaf holds…
- A query scans a table of 11 pages sequentially, 5 times in a row, with a buffer pool of 10 pages (initially empty). How many buffer hits…