Lesson 13 of 13 · 22 min
Classic grouping mistakes
By the end of this lesson you can review a grouped query, identify grain errors, double counting and averages of averages, and rewrite it so the numbers are correct.
Every grouped query rests on one question: what does one input row represent, and what should one output row represent? The first is the table's grain (one row per order, per order line, per payment…); the second is the report's grain (one row per day, per channel…). Almost every aggregation bug is a mismatch between the two. This lesson collects the four classic ones and a checklist to catch them.
This lesson, its 4 graded exercises and every other Members lesson in SQL Quest come with a Formula Quest membership that includes SQL (Single Quest with SQL selected, Quest Trio including SQL, or Quest Unlimited), or with SQL access from your organization.
Free to everyone: all of SQL Foundations and Retrieving and Filtering Data, the first lesson of every track, the playground, the dataset library and the SQL reference. See free lessons