QuestionQ18

Analyzing Queries

A data analyst needs to identify product categories that satisfy two conditions:

  1. Each category has more than 10 products.
  2. The category’s average product price exceeds $50.

Which SQL statement uses aggregate functions to return only the categories that meet these conditions?

  • A SELECT category, COUNT() FROM products GROUP BY category HAVING COUNT() > 10 AND AVG(price) > 50;
  • B SELECT category, COUNT() FROM products WHERE COUNT() > 10 GROUP BY category HAVING AVG(price) > 50;
  • C SELECT category, COUNT() FROM products HAVING COUNT() > 10 GROUP BY category WHERE AVG(price) > 50;
  • D SELECT category, COUNT() FROM products GROUP BY category WHERE COUNT() > 10 AND AVG(price) > 50;
Explanation

HAVING filters grouped results using aggregate expressions. Grouping by category and applying COUNT(*) > 10 AND AVG(price) > 50 in the HAVING clause returns only categories satisfying both aggregate criteria.

Community Discussion

No comments yet. Be the first to start the discussion!