diff --git a/02-sql-aggregation.md b/02-sql-aggregation.md index a8044d69..6f27f096 100644 --- a/02-sql-aggregation.md +++ b/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; ``` ::::::::::::::::::::::::: diff --git a/md5sum.txt b/md5sum.txt index 582d5799..431fc664 100644 --- a/md5sum.txt +++ b/md5sum.txt @@ -7,7 +7,7 @@ "index.md" "cfdee7444b27a96171c25e1d4915e1e9" "site/built/index.md" "2023-06-07" "episodes/00-sql-introduction.md" "e8ac248b290e74c264817c41dbbad159" "site/built/00-sql-introduction.md" "2024-09-11" "episodes/01-sql-basic-queries.md" "256c3e6db6f844897ae9643129609c31" "site/built/01-sql-basic-queries.md" "2024-09-11" -"episodes/02-sql-aggregation.md" "07784e3014a42660059c18e6ba71f26d" "site/built/02-sql-aggregation.md" "2023-04-21" +"episodes/02-sql-aggregation.md" "43e9c574b465bf76715a10bf3f31c8e4" "site/built/02-sql-aggregation.md" "2025-01-24" "episodes/03-sql-joins.md" "7ce22e3c1e1719ad50edbcd72e333013" "site/built/03-sql-joins.md" "2024-06-03" "instructors/instructor-notes.md" "105728ef72c768e968ca9d11c2a14109" "site/built/instructor-notes.md" "2023-04-21" "learners/discuss.md" "0ff402a01b3496a37bf790b8eae69b76" "site/built/discuss.md" "2024-09-11"