From 4e1bcb583b34ea498699476ee8f62322ffe9a731 Mon Sep 17 00:00:00 2001 From: Chris Roat <1053153+chrisroat@users.noreply.github.com> Date: Mon, 14 Sep 2020 16:26:52 -0700 Subject: [PATCH 1/2] Explain NULLs when teaching count The removes a small oversight in the current explanation, that columns with NULL values are not counted. It also teases the fuller explanation of NULL and aggregation that comes later. --- _episodes/06-agg.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/_episodes/06-agg.md b/_episodes/06-agg.md index 4a753759..58ba3818 100644 --- a/_episodes/06-agg.md +++ b/_episodes/06-agg.md @@ -95,11 +95,15 @@ SELECT sum(reading) FROM Survey WHERE quant = 'sal'; |64.83 | We used `count(reading)` here, -but we could just as easily have counted `quant` -or any other field in the table, -or even used `count(*)`, +but could have used `count(*)`, since the function doesn't care about the values themselves, just how many values there are. +Even a column other than `reading` could be used, +but note that any `NULL` value will not be counted +(try counting the `person` column instead). +This perhaps non-obvious behavior +of aggregation functions is covered later +in this episode. SQL lets us do several aggregations at once. We can, From 7fff12b8e358bb004a724e62b5375a0e35082db7 Mon Sep 17 00:00:00 2001 From: Chris Roat <1053153+chrisroat@users.noreply.github.com> Date: Mon, 14 Sep 2020 21:49:44 -0700 Subject: [PATCH 2/2] Clarify how count works - counts rows, not values - be more specific about the NULL in the person column of the dataset --- _episodes/06-agg.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/_episodes/06-agg.md b/_episodes/06-agg.md index 58ba3818..69f37bba 100644 --- a/_episodes/06-agg.md +++ b/_episodes/06-agg.md @@ -97,10 +97,11 @@ SELECT sum(reading) FROM Survey WHERE quant = 'sal'; We used `count(reading)` here, but could have used `count(*)`, since the function doesn't care about the values themselves, -just how many values there are. +just how many rows there are. Even a column other than `reading` could be used, but note that any `NULL` value will not be counted -(try counting the `person` column instead). +(to see, try `count`ing the `person` column, which contains a +row with a `NULL`). This perhaps non-obvious behavior of aggregation functions is covered later in this episode.