CS FundamentalsModerateGATE 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). Which rows does this query return? SELECT region, SUM(amt) FROM Bill GROUP BY region HAVING COUNT(amt) >= 2;

  1. A. ('E', 750) and ('W', 750)
  2. B. ('E', 750) and ('W', NULL)
  3. C. ('E', 750) only
  4. D. ('E', 750), ('W', 750) and (NULL, 200)

Correct answer: A. ('E', 750) and ('W', 750)

Each of E and W has two non-NULL amounts (300 + 450 = 750), and SUM simply skips the NULL; the NULL-region group has COUNT(amt) = 1 and fails HAVING.

More DBMS and SQL questions

Exams that ask this topic