CS FundamentalsVery hardGATE CS (PYQ pattern)

Table M(g, v): (x,10), (x,NULL), (x,20), (y,NULL), (y,NULL), (z,30). How many groups does SELECT g FROM M GROUP BY g HAVING COUNT(*) > COUNT(v) return, and what does SELECT SUM(v) FROM M WHERE g = 'y' return?

  1. A. 2 groups; SUM is 0
  2. B. 1 group; SUM is NULL
  3. C. 2 groups; SUM is NULL
  4. D. 3 groups; SUM is NULL

Correct answer: C. 2 groups; SUM is NULL

COUNT(*) counts rows and COUNT(v) skips NULLs: x has 3 > 2, y has 2 > 0, z has 1 = 1, so x and y qualify (2 groups). SUM over only NULL values is NULL, not 0.

More DBMS and SQL questions

Exams that ask this topic