Skip to content

Commit

Permalink
Clarify aggregation challenge solution
Browse files Browse the repository at this point in the history
- Explain the SQL query
- Use full words for the column alias, rather than a single letter
  • Loading branch information
Joe-Heffer-Shef authored Jan 10, 2025
1 parent 3d3515b commit 366c258
Showing 1 changed file with 6 additions and 1 deletion.
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`.
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
FROM species
GROUP BY taxa
HAVING n > 10;
Expand Down

0 comments on commit 366c258

Please sign in to comment.