Summarize groups with GROUP BY and HAVING
GROUP BY collects rows with the same key so COUNT, SUM or AVG can summarize them. WHERE filters rows before grouping; HAVING filters groups after aggregation.
SELECT category, COUNT(*) AS product_count FROM products GROUP BY category HAVING COUNT(*) >= 2;Common misunderstanding
An unaggregated product name does not represent an entire category. Return a grouping key or an aggregate expression.
Related missions
Practice opens in this page’s language. Change it in the practice options at any time.