Loading…
GROUP BY is what makes aggregate functions truly powerful. It groups rows with the same value and lets you calculate aggregates per group.
SELECT COUNT(*) FROM products;
-- Returns: 5 (total count of ALL products)
SELECT category, COUNT(*) FROM products
GROUP BY category;
-- Returns: count PER category
-- Electronics 2
-- Office 2
-- Books 1
GROUP BY columnGROUP BY customer_idGROUP BY monthGROUP BY departmentEvery column in SELECT must either be:
GROUP BY clause, ORCount how many products are in each category.
Downloading SQL engine… (one-time)
This runs entirely in your browser and is cached for next time.