strawquery PT
All lessons

Lesson 23 of 30

GROUP BY

Today at the studio

A single number is nice, but the board wants one number per genre, per department, per show. "The same question," says Rin, "asked many times, once for each group."

The idea

GROUP BY column puts rows with the same value in one group, and every aggregate in SELECT is calculated once per group.

Each column in SELECT must either be in GROUP BY or be inside an aggregate function. You can join tables first and then group the result, which is how you get a title or a name next to a total.

Example

SELECT species, COUNT(*)
FROM characters
GROUP BY species

Your turn

0 of 4 questions

Question 1 of 4

Show each genre and how many shows it has.

Unofficial fan project. Titles belong to their creators and rights holders.