CS FundamentalsVery hardGATE 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 MAX(amt) = MIN(amt);

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

Correct answer: B. Lata, Mona and Nair

MAX and MIN skip NULLs. Lata has only 450 and Mona only 300 among non-NULL values, so both pass with Nair (200); Kavi has 300 and 450. Thinking a NULL makes the group fail drops Lata and Mona.

More DBMS and SQL questions

Exams that ask this topic