CS FundamentalsHardGATE CS

O(cust, item) = (c1, x), (c1, x), (c1, y), (c2, z), (c2, NULL), (c3, NULL), (c3, NULL), (c4, w), (c4, w), (c5, p), (c5, q), (c5, p). How many rows does SELECT cust FROM O GROUP BY cust HAVING COUNT(DISTINCT item) = COUNT(item) return?

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

Correct answer: A. 2

COUNT(item) ignores NULLs and COUNT(DISTINCT item) ignores NULLs and duplicates, so the groups where all non-NULL items are different qualify (customers with only NULLs give 0 = 0 and also qualify): 2 groups. Using COUNT(*) instead would return 0.

More DBMS and SQL questions

Exams that ask this topic