CS FundamentalsHardGATE CS (PYQ pattern)

G(g, x): (a,5), (a,7), (b,4), (b,4), (b,4), (c,20), (d,NULL), (d,1). How many groups does SELECT g FROM G GROUP BY g HAVING SUM(x) > (SELECT AVG(s) FROM (SELECT SUM(x) AS s FROM G GROUP BY g)) return?

  1. A. 4
  2. B. 5
  3. C. 0
  4. D. 3

Correct answer: D. 3

Group sums are a = 12, b = 12, c = 20, d = 1; their average is 11.25. Groups with a sum above 11.25: a (12), b (12) and c (20), so 3 groups; d (1) is below.

More DBMS and SQL questions

Exams that ask this topic