Group Things Together

Group rows and apply aggregate functions to groups.

You already know how to calculate totals, averages, and counts. But what if you want those numbers for each group, like each city or pet type? Instead of just “How many pets?” You want: “How many pets of each type?” That’s where GROUP BY shines.

Goal

You’ll aim to:

  • Group rows by a shared value (like city or type).

  • Use aggregate functions within groups.

Tables

Here is the people and pets table that we will use in this lesson:

The people table

Get hands-on with 1400+ tech skills courses.