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). For how many customers do SUM(amt) * 1.0 / COUNT(*) and AVG(amt) give different values?

  1. A. 1
  2. B. 3
  3. C. 0
  4. D. 2

Correct answer: D. 2

AVG divides by the non-NULL count while COUNT(*) counts every row. Only Lata (450 / 2 vs 450) and Mona (300 / 2 vs 300) have NULL amounts, so they differ for 2 customers.

More DBMS and SQL questions

Exams that ask this topic