diff --git a/episodes/02-sql-aggregation.md b/episodes/02-sql-aggregation.md index a8044d69..6f27f096 100644 --- a/episodes/02-sql-aggregation.md +++ b/episodes/02-sql-aggregation.md @@ -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; ``` :::::::::::::::::::::::::