CodeAgeBy Sitezack
SQL for ProsSQL with SQLite0 XP
Chapter progress0/6

Lesson 5 of 7

GROUP BY: aggregate by group

Aggregate functions (COUNT, SUM, AVG…) combine with GROUP BY to compute per group: orders per customer, total per city…

SELECT customer_id, COUNT(*), SUM(amount) FROM orders GROUP BY customer_id — one result row per customer.

SELECT city, COUNT(*) FROM customers GROUP BY city;

🎯 Exercise

On the orders table: return, per customer_id, the number of orders (COUNT(*)) and the sum of amounts (SUM(amount)). Group by customer_id and sort by customer_id.

PRO lesson

This advanced chapter is part of CodeAge PRO. Unlock it to keep your adventure going.

Discover PRO