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
| id | customer | region | amount |
|---|---|---|---|
| 1042 | Northwind | Otago | 1250 |
| 1043 | Kea Ltd | Waikato | 840 |
| 1044 | Halcyon | Otago | 2110 |
| 1045 | Brightsmith | Auckland | 560 |
4 more rows in the table. Your query sees all 8.