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, AVG(amt), COUNT(amt), COUNT(*)
FROM Sale
WHERE region = 'S'
GROUP BY region;
  1. A. S, 250, 1, 2
  2. B. S, 250, 2, 2
  3. C. S, 125, 2, 2
  4. D. S, 125, 1, 2

Correct answer: A. S, 250, 1, 2

The S group has two rows, one with NULL amt. AVG and COUNT(amt) ignore the NULL (250 and 1); COUNT(*) still counts both rows.

More DBMS and SQL questions

Exams that ask this topic