WeCodeAcademy

GROUP BY

GROUP BY splits rows into groups and runs the aggregate once per group. Compare: how many customers live in each city?

Examplesql
Open in editor »

Average price per category, sorted:

Examplesql
Open in editor »

Every column in SELECT must either be in GROUP BY or be inside an aggregate function.

Quick check

What does `SELECT city, COUNT(*) FROM customers GROUP BY city` return?

Your turn: write the code

Return each customer_id from orders with how many orders they placed, sorted by customer_id.

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.