CS FundamentalsHardGATE CS · Amazon/Microsoft SDE MCQ

Table Bill(id, cust, region, amt) rows: (1, 'Kavi', 'E', 300), (2, 'Lata', 'W', NULL), (3, 'Kavi', 'E', 450), (4, 'Mona', 'W', 300), (5, 'Nair', NULL, 200), (6, 'Lata', 'W', 450), (7, 'Mona', 'E', NULL). This statement is run once: UPDATE Bill SET amt = amt + 100 WHERE amt < (SELECT AVG(amt) FROM Bill); What is SUM(amt) afterwards?

  1. A. 2000
  2. B. 2200
  3. C. 1900
  4. D. 2100

Correct answer: A. 2000

The average is 340, so bills 1, 4 and 5 (300, 300, 200) each gain 100; NULL amounts fail the comparison and stay NULL. 1700 + 300 = 2000. Standard SQL evaluates the subquery as of before the update.

More DBMS and SQL questions

Exams that ask this topic