Students summarise many rows into one value with COUNT, SUM, AVG and MAX, filtered by WHERE.
Open these in Waypoints Prepare with one click. To share a file another way, copy its address and paste it into Load URL, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
Predict and Run 8 min · Investigate 7 min · Modify and Make 10 min
On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.
Pairs guess a summary (the average length of a rock song), then run it. Who was closest?
Expecting a list back. Ask how many values a count can be.
| What you will see | A question to ask | The fix |
|---|---|---|
| A column name and COUNT(*) together give an odd result. | Is the answer one value or a list? | Summaries give one row. Mixing in a plain column needs GROUP BY, which is the next lesson. |
| COUNT(*) shows 15 when it should show fewer. | Did the WHERE line stay? | Add the WHERE line back before the semicolon. |
One possible solution for each task. Other correct programs are fine.
SELECT COUNT(*)
FROM songs
WHERE artist = 'Kito';
SELECT AVG(seconds)
FROM songs
WHERE genre = 'pop';
Stretch: Show the count and the average length in one query.
Support: Give the whole query with the function name missing.
What is the difference between SELECT title and SELECT COUNT(*)?
SELECT title gives one row for each song. COUNT(*) gives one row with how many rows there are.
Next lesson: one count for each genre at once, with GROUP BY.