CS FundamentalsModerateProduct placement · SQL round

Table Product(pid, cat, price) rows: (1, 'X', 10), (2, 'X', 20), (3, 'Y', 20), (4, NULL, 30), (5, 'Y', NULL), (6, 'Z', 5). What does this query return?

Table Product(pid, cat, price) rows: (1, 'X', 10), (2, 'X', 20), (3, 'Y', 20), (4, NULL, 30), (5, 'Y', NULL), (6, 'Z', 5). What does this query return?
SELECT cat, MAX(price)
FROM Product
WHERE cat IS NOT NULL
GROUP BY cat
HAVING MIN(price) >= 10
ORDER BY cat;
  1. A. (X, 20), (Y, 20)
  2. B. (X, 20)
  3. C. (Y, 20)
  4. D. (X, 20), (Y, 20), (Z, 5)

Correct answer: A. (X, 20), (Y, 20)

X: min 10 passes. Y: prices 20 and NULL, MIN ignores NULL so min = 20, passes. Z: min 5 fails.

More DBMS and SQL questions

Exams that ask this topic