Skip to content

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
First rows of the tickets table
idcustomeragentminutesrating
1NorthwindAna125
2Kea LtdBo453
3HalcyonAna30NULL
4BrightsmithCy84

4 more rows in the table. Your query sees all 8.