Español

For teachers · 50 minutes

← Ready-to-teach lessons

GROUP BY and HAVING lesson

Counting, summing and filtering groups in 50 minutes, with the difference between WHERE and HAVING made clear. With a printable worksheet.

Goal

Every student can summarize a table by groups and knows when to filter rows and when to filter groups.

Lesson plan

0–5 minIntroduce the topic on the board with one example query.
5–20 minArcade, in pairs or alone. Arcade world 2: The Sorter, The Loot, The Podium and the boss, The Late Filter.
20–35 minWorksheet: six questions on the same tables.
35–45 minArcade again: go back for three stars on the levels that were hardest.
45–50 minClass discussion with the questions below. Whoever beat the boss hands in their certificate code.

Materials

SQL arcadeArcade world 2: The Sorter, The Loot, The Podium and the boss, The Late Filter.

Mistakes you'll see

For the class discussion

Evidence

When a student beats a boss, the arcade gives a certificate with a code. Ask for it as the submission and check it here: check codes →

Student worksheet

Ready to print, no answers.

Worksheet PDF
SQL ARCADE
Name: ______________________________Date: ____________

GROUP BY and HAVING lesson

thefts
idsuspect_idcityloot
12Salt Harbor1200
22Salt Harbor800
34San Ciro300
45Salt Harbor5000
58Salt Harbor450
68Lumen Bay950
78San Ciro150
81Lumen Bay2200
9NULLLumen Bay700
  1. How many thefts are there in total?
  2. How many thefts there were in each city.
  3. The total loot in each city.
  4. The highest loot in each city.
  5. The cities with more than 2 thefts.
  6. Counting only thefts of 500 or more, the cities with at least 3.

casoabiertogame.com · SQL arcade and detective cases, free for the classroom

Want the answer key?

The worksheet answers and the solutions to all 28 cases aren't published, so students won't find them. Write to us from your institutional email and we'll send them, at no cost.

Request the answer key

The arcade, the lessons and the first two cases are free and need no account. For your group to have all 28 cases, the classroom license is free too: how to request it →