Lesson 23 of 30
77%
Aggregate Functions
Aggregate functions squash many rows into one number.
COUNT, SUM, AVG, MIN, and MAX are the everyday five.
COUNT
COUNT(*) counts rows. COUNT(age) skips NULL ages.
sql
Result
| total_students |
|---|
| 5 |
1 row
SUM and AVG
sql
Result
| total_points | avg_points |
|---|---|
| 273 | 91.0000 |
1 row
MIN and MAX
sql
Result
| youngest | oldest |
|---|---|
| 10 | 13 |
1 row
COUNT DISTINCT
How many different cities?
sql
Result
| cities |
|---|
| 5 |
1 row
Tip: Give aggregates a nickname with AS. The default names are ugly.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.