SQL GROUP BY Practice
GROUP BY helps you summarize rows into useful totals, counts, and averages. Practice common aggregate query patterns with short SQL examples.
GROUP BY practice is about moving from individual rows to summaries. The important shift is deciding which column creates each group and which aggregate describes that group.
Read each prompt by naming the group first, then the calculation. If a grouped result needs filtering, decide whether the condition belongs in WHERE or HAVING.
- COUNT, SUM, AVG, MIN, and MAX
- Grouping rows by one column
- Filtering grouped results with HAVING
Example practice questions
Try these samples, then continue into the SQL Practice Labfor guided browser-based practice.
Count orders by status.
Answer: SELECT status, COUNT(*) FROM orders GROUP BY status;
Find total sales by customer_id.
Answer: SELECT customer_id, SUM(total) FROM orders GROUP BY customer_id;
Find average price by category.
Answer: SELECT category, AVG(price) FROM products GROUP BY category;
Count users by country.
Answer: SELECT country, COUNT(*) FROM users GROUP BY country;
Filter grouped statuses with more than 10 orders.
Answer: SELECT status, COUNT(*) FROM orders GROUP BY status HAVING COUNT(*) > 10;
Find the highest order total by customer_id.
Answer: SELECT customer_id, MAX(total) FROM orders GROUP BY customer_id;
Count products in each category.
Answer: SELECT category, COUNT(*) FROM products GROUP BY category;