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 1/4] 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; From af73a87c4c7fb3d8c4d334544a6b28e6d5856913 Mon Sep 17 00:00:00 2001 From: Joe Heffer <60133133+Joe-Heffer-Shef@users.noreply.github.com> Date: Thu, 23 Jan 2025 09:13:50 +0000 Subject: [PATCH 2/4] Update episodes/02-sql-aggregation.md Co-authored-by: James Foster <38274066+jd-foster@users.noreply.github.com> --- episodes/02-sql-aggregation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/episodes/02-sql-aggregation.md b/episodes/02-sql-aggregation.md index 91aaaec4..336c52f8 100644 --- a/episodes/02-sql-aggregation.md +++ b/episodes/02-sql-aggregation.md @@ -226,7 +226,7 @@ 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`. +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. From 7ce40747235102097fa0b2552c49a0a95efe97ab Mon Sep 17 00:00:00 2001 From: Joe Heffer <60133133+Joe-Heffer-Shef@users.noreply.github.com> Date: Thu, 23 Jan 2025 09:13:59 +0000 Subject: [PATCH 3/4] Update episodes/02-sql-aggregation.md Co-authored-by: James Foster <38274066+jd-foster@users.noreply.github.com> --- episodes/02-sql-aggregation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/episodes/02-sql-aggregation.md b/episodes/02-sql-aggregation.md index 336c52f8..1445c9dd 100644 --- a/episodes/02-sql-aggregation.md +++ b/episodes/02-sql-aggregation.md @@ -232,7 +232,7 @@ Only those `taxa` values that have more than ten records will be included becaus This filtering is applied _after_ grouping has been done. ```sql -SELECT taxa, COUNT(*) AS species_count +SELECT taxa, COUNT(*) AS taxa_count FROM species GROUP BY taxa HAVING n > 10; From 81295c0e0045055262d34b3ce6abae7e42436aca Mon Sep 17 00:00:00 2001 From: Joe Heffer <60133133+Joe-Heffer-Shef@users.noreply.github.com> Date: Thu, 23 Jan 2025 09:14:27 +0000 Subject: [PATCH 4/4] Fix syntax for field name --- episodes/02-sql-aggregation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/episodes/02-sql-aggregation.md b/episodes/02-sql-aggregation.md index 1445c9dd..6f27f096 100644 --- a/episodes/02-sql-aggregation.md +++ b/episodes/02-sql-aggregation.md @@ -235,7 +235,7 @@ This filtering is applied _after_ grouping has been done. SELECT taxa, COUNT(*) AS taxa_count FROM species GROUP BY taxa -HAVING n > 10; +HAVING taxa_count > 10; ``` :::::::::::::::::::::::::