CS FundamentalsModerateGATE CS · SQL

Table Sale(id, rep, region, amt) rows: (1, 'Ira', 'N', 100), (2, 'Jai', 'S', 250), (3, 'Ira', 'S', NULL), (4, 'Kim', 'N', 300), (5, 'Jai', 'N', 150), (6, 'Ira', 'N', 200), (7, 'Lal', NULL, 120). What does this query return?

Table Sale(id, rep, region, amt) rows: (1, 'Ira', 'N', 100), (2, 'Jai', 'S', 250), (3, 'Ira', 'S', NULL), (4, 'Kim', 'N', 300), (5, 'Jai', 'N', 150), (6, 'Ira', 'N', 200), (7, 'Lal', NULL, 120). What does this query return?
SELECT rep, SUM(amt)
FROM Sale
GROUP BY rep
HAVING SUM(amt) > 250
ORDER BY rep;
  1. A. (Jai, 400)
  2. B. (Ira, 300), (Jai, 400), (Kim, 300), (Lal, 120)
  3. C. (Jai, 400), (Kim, 300)
  4. D. (Ira, 300), (Jai, 400), (Kim, 300)

Correct answer: D. (Ira, 300), (Jai, 400), (Kim, 300)

SUM ignores Ira's NULL sale, so Ira totals 100 + 200 = 300 (not NULL). Jai 400, Kim 300, Lal 120 — three groups exceed 250.

More DBMS and SQL questions

Exams that ask this topic