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?

  1. A. 117 and 4
  2. B. 87 and 3
  3. C. 117 and 3
  4. 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

Exams that ask this topic