CS FundamentalsHardGATE CS (PYQ pattern)
UA(id, g, x): (1,1,10), (2,2,20), (3,3,30), (4,1,40). UB(g, bonus): (1,5), (2,7). After UPDATE UA SET x = x + (SELECT bonus FROM UB WHERE UB.g = UA.g); what are SUM(x) and COUNT(x) over UA?
- A. 117 and 4
- B. 87 and 3
- C. 117 and 3
- D. 87 and 4
Correct answer: B. 87 and 3
For g = 3 the scalar subquery finds no row and returns NULL, so x + NULL = NULL: that row's x becomes NULL (it is not left unchanged). SUM skips it (15 + 27 + 45 = 87) and COUNT(x) = 3.
More DBMS and SQL questions
- IA(x): 1, 2, 3, NULL, 5 and IB(y): 2, 2, 5, 7. Let p = rows of IA satisfying x IN (SELECT y FROM IB), q = rows of IA satisfying x NOT IN…
- T1 executes W1(A), C1 and T2 executes R2(A), W2(B), C2, each in the stated order. Among all interleavings of the five operations, how many…
- Strict two-phase locking with shared locks for reads and exclusive for writes (a transaction already holding S can upgrade to X only if no…
- Transactions T1..T5 have timestamps equal to their numbers (T1 is oldest). Seven independent lock conflicts occur, written (requester…
- Log (LSN: record): 1: T1 update P1; 2: T2 update P2; 3: T1 update P3; 4: begincheckpoint, whose endcheckpoint records ATT = {T1, T2} and…
- Log (LSN: record): 1: T1 update P1; 2: T2 update P2; 3: T1 update P3; 4: begincheckpoint, whose endcheckpoint records ATT = {T1, T2} and…