Skip to content

Commit 2094024

Browse files
Clarify aggregation challenge solution (#382)
- Add a paragraph to explain the SQL query in the solution - Use full words for the column alias, rather than a single letter
1 parent 53b4fc4 commit 2094024

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

episodes/02-sql-aggregation.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,16 @@ Write a query that returns, from the `species` table, the number of
226226

227227
## Solution
228228

229+
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.
230+
The `GROUP BY` clause means the query will create an aggregated table with one row for each taxa.
231+
Only those `taxa` values that have more than ten records will be included because of the `HAVING` clause.
232+
This filtering is applied _after_ grouping has been done.
233+
229234
```sql
230-
SELECT taxa, COUNT(*) AS n
235+
SELECT taxa, COUNT(*) AS taxa_count
231236
FROM species
232237
GROUP BY taxa
233-
HAVING n > 10;
238+
HAVING taxa_count > 10;
234239
```
235240

236241
:::::::::::::::::::::::::

0 commit comments

Comments
 (0)