Step 1 of 14
SQL GROUP BY and aggregate functions: one answer per group
In this lesson you practise SQL GROUP BY and aggregate functions on one small sales table: you group orders by region, rep and product, and count, total and average each group. Then you filter groups with HAVING, see how it differs from WHERE, and check your answers in exercises.
Here is the whole idea in one picture. Each card is one order. GROUP BY sorts the orders into buckets, one bucket per region, and the aggregate turns each bucket into a single number. Change the column or the function and watch the rows move.
In this lesson you'll
- turn many rows into one number with COUNT, SUM, AVG, MIN and MAX
- group rows by one column, then by two, and read the result
- filter rows with WHERE and buckets with HAVING, and know which to use
- count correctly when some values are NULL
About 75 minutes, with a practice set halfway, a short check, a playground, a second practice set and a final quiz.