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). What does this query return? SELECT COUNT(*), COUNT(amt), COUNT(DISTINCT amt), COUNT(region) FROM Bill;

  1. A. 7, 5, 4, 6
  2. B. 7, 7, 3, 7
  3. C. 7, 5, 3, 6
  4. D. 7, 5, 3, 7

Correct answer: C. 7, 5, 3, 6

COUNT(*) counts all 7 rows; COUNT(amt) skips the two NULL amounts (5); DISTINCT over non-NULL amounts gives {200, 300, 450} = 3; COUNT(region) skips Nair's NULL region (6).

More DBMS and SQL questions

Exams that ask this topic