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 1 commit
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
7 changes: 6 additions & 1 deletion episodes/02-sql-aggregation.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,13 @@ Write a query that returns, from the `species` table, the number of

## Solution

This query counts the number of species records that contain each value of the `taxa` field and names that result `species_count`.
Joe-Heffer-Shef marked this conversation as resolved.
Show resolved Hide resolved
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 species_count
Joe-Heffer-Shef marked this conversation as resolved.
Show resolved Hide resolved
FROM species
GROUP BY taxa
HAVING n > 10;
Joe-Heffer-Shef marked this conversation as resolved.
Show resolved Hide resolved
Expand Down