Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify aggregation challenge solution #382

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions episodes/02-sql-aggregation.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,16 @@ Write a query that returns, from the `species` table, the number of

## Solution

This query counts the number of times each value (Bird, Rabbit, Reptile or Rodent) in the `taxa` field occurs, defining a new field named `taxa_count` to hold the result.
The `GROUP BY` clause means the query will create an aggregated table with one row for each taxa.
Only those `taxa` values that have more than ten records will be included because of the `HAVING` clause.
This filtering is applied _after_ grouping has been done.

```sql
SELECT taxa, COUNT(*) AS n
SELECT taxa, COUNT(*) AS taxa_count
FROM species
GROUP BY taxa
HAVING n > 10;
HAVING taxa_count > 10;
```

:::::::::::::::::::::::::
Expand Down