SLSkillLoop
SQL practice

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.

How to practice SQL GROUP BY

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.

What to focus on
  • 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.

1

Count orders by status.

Answer: SELECT status, COUNT(*) FROM orders GROUP BY status;

2

Find total sales by customer_id.

Answer: SELECT customer_id, SUM(total) FROM orders GROUP BY customer_id;

3

Find average price by category.

Answer: SELECT category, AVG(price) FROM products GROUP BY category;

4

Count users by country.

Answer: SELECT country, COUNT(*) FROM users GROUP BY country;

5

Filter grouped statuses with more than 10 orders.

Answer: SELECT status, COUNT(*) FROM orders GROUP BY status HAVING COUNT(*) > 10;

6

Find the highest order total by customer_id.

Answer: SELECT customer_id, MAX(total) FROM orders GROUP BY customer_id;

7

Count products in each category.

Answer: SELECT category, COUNT(*) FROM products GROUP BY category;