Country: Philippines
You are in the Philippines edition. Type your country to switch.
Nigeria
Loading every country…
No country matches. Check the spelling, or choose "Any country" for the Global edition.
You are learning in the Philippines edition, with examples in pesos and from the Philippines.
Your learning profile
Data skills: SQL and Python basics · Lesson 3 of 7
Summarising with SQL: GROUP BY, COUNT, SUM and AVG
Summaries turn many rows into a few answers: how many orders, how many units, how much revenue per region. This lesson covers COUNT, SUM and AVG, grouping with GROUP BY, the difference between WHERE and HAVING, and the order in which a database reads a query.
This lesson is complete in writing. A video for it is on its way.
What you will learn
- By the end you can summarise a whole table with COUNT, SUM and AVG.
- You can write a GROUP BY query that returns one row per group, such as one per city.
- You can choose correctly between WHERE and HAVING.
- You can explain the order in which a database reads a query, and use it to fix common errors.
Key terms in this lesson
- Aggregate function
- A function that turns many values into one summary value, such as COUNT for how many rows, SUM for a total, AVG for an average, or MIN and MAX.
- GROUP BY clause
- The part of an SQL query that collects rows sharing a value, such as the same region, so that aggregate functions return one summary row per group.
- HAVING clause
- The part of an SQL query that filters groups after they are summarised, for example keeping only regions whose total revenue is above a chosen amount.
- Logical query order
- The order in which a database works through an SQL query: FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY and LIMIT, which differs from the order it is written in.
- Pivot table
- A spreadsheet tool that summarises a long table by groups, such as totals by year and sector.
- Step 1: Summing up a whole table, not started
- Step 2: One row per group with GROUP BY, not started
- Step 3: Averages and what they hide, not started
- Step 4: WHERE filters rows, HAVING filters groups, not started
- Step 5: The order a query is read in, not started
- Step 6: Checking a summary before you share it, not started
About 7 min of reading
Step 1 of 6
Summing up a whole table
Opening this step…
Step 2 of 6
One row per group with GROUP BY
This step opens when you finish the one above.
Step 3 of 6
Averages and what they hide
This step opens when you finish the one above.
Step 4 of 6
WHERE filters rows, HAVING filters groups
This step opens when you finish the one above.
Step 5 of 6
The order a query is read in
This step opens when you finish the one above.
Step 6 of 6
Checking a summary before you share it
This step opens when you finish the one above.
Key takeaways
The key takeaways open when you finish every step.
Lesson quiz
6 questions. You need 85% to pass.
The quiz opens when you finish every step.
Stockertim Learn is education. It explains how investing works and never recommends buying or selling anything.
Popular this week: Basics: BeginnerStock market: Intermediate