Skip to content

GROUP BY

One row per region instead of one per order

0 of 3 done · Lesson 5 of 8

Understand

Your manager has a table with one row per order and wants one row per region. Not a filter, not a sort. Fewer rows come out than went in, with the amounts added up inside each one. That collapsing is what GROUP BY does, and it is the first thing in SQL with no spreadsheet equivalent you already know.

SELECT what_identifies_the_group, what_to_work_out
FROM where_it_lives
GROUP BY the_same_thing_again;
SELECTwhat identifies the groupFROMwhich tableGROUP BYthe same thing again

The tables you are working with

8 rows
First rows of the orders table
idcustomerregionamount
1042NorthwindOtago1250
1043Kea LtdWaikato840
1044HalcyonOtago2110
1045BrightsmithAuckland560

4 more rows in the table. Your query sees all 8.