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 customers does this query return? SELECT cust FROM Bill GROUP BY cust HAVING COUNT(*) > COUNT(amt);

  1. A. Lata and Mona
  2. B. Kavi and Lata
  3. C. Mona only
  4. D. Lata only

Correct answer: A. Lata and Mona

COUNT(*) exceeds COUNT(amt) exactly when a group has a NULL amount: Lata (bill 2) and Mona (bill 7). Kavi's two bills both have amounts.

More DBMS and SQL questions

Exams that ask this topic