CS FundamentalsModerateTCS Digital · Infosys SP · GATE CS

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 region, COUNT(*)
FROM Sale
WHERE amt > 120
GROUP BY region
ORDER BY region;
  1. A. (N, 4), (S, 1)
  2. B. (N, 4), (S, 2)
  3. C. (N, 3), (S, 2)
  4. D. (N, 3), (S, 1)

Correct answer: D. (N, 3), (S, 1)

WHERE removes rows before grouping: N keeps 300, 150, 200 (100 fails); S keeps only 250 (NULL fails); Lal's 120 is not > 120.

More DBMS and SQL questions

Exams that ask this topic