From 366c2585d7986ba28cd69125f7bb65f08814fe40 Mon Sep 17 00:00:00 2001 From: Joe Heffer <60133133+Joe-Heffer-Shef@users.noreply.github.com> Date: Fri, 10 Jan 2025 11:26:12 +0000 Subject: [PATCH] Clarify aggregation challenge solution - Explain the SQL query - Use full words for the column alias, rather than a single letter --- episodes/02-sql-aggregation.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/episodes/02-sql-aggregation.md b/episodes/02-sql-aggregation.md index a8044d69..91aaaec4 100644 --- a/episodes/02-sql-aggregation.md +++ b/episodes/02-sql-aggregation.md @@ -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;