COUNT, SUM & AVG
Turn a column of numbers into one number that answers the question
0 of 3 done · Lesson 4 of 8
Understand
The support table has one row per ticket, and nobody wants to read eight rows. They want a number: how many tickets, how long they took, how happy people were. COUNT, SUM and AVG each collapse a column into a single answer. The catch is what they do with the rows where the value is missing, and that is where most wrong answers in this lesson come from.
SELECT COUNT(*), SUM(which_column), AVG(which_column) FROM where_it_lives WHERE which_rows_to_include;
SELECTwhat to work outFROMwhich tableWHEREwhich rows to include
The tables you are working with
8 rows
| id | customer | agent | minutes | rating |
|---|---|---|---|---|
| 1 | Northwind | Ana | 12 | 5 |
| 2 | Kea Ltd | Bo | 45 | 3 |
| 3 | Halcyon | Ana | 30 | NULL |
| 4 | Brightsmith | Cy | 8 | 4 |
4 more rows in the table. Your query sees all 8.