Chapter 3 Revision: Aggregations & Grouping 📊
You have graduated from single-row querying to multi-row summary analytics!
Aggregations and grouping are fundamental for dashboards, reporting metrics, KPI computation, and database interview problems.
Test your mastery with these flashcards and conceptual quizzes.
Active Recall Flashcards 🎴
Click each card to test your retention before checking the answer.
When would COUNT(*) and COUNT(column_name) produce different numbers on the exact same table?
COUNT(*) counts all rows, while COUNT(column_name) skips rows where that column is NULL.Explain the difference between WHERE and HAVING in one sentence.
What happens if you run 'SELECT category, product_name, AVG(price) FROM products GROUP BY category;'?
product_name is neither in the GROUP BY clause nor enclosed in an aggregate function, violating the Golden Rule of SQL grouping.How does the AVG() function calculate the mean when some rows have NULL values?
SUM(column) / COUNT(column). It completely excludes NULL rows from both the numerator and the denominator, rather than treating them as 0.Where do GROUP BY and HAVING sit in the full SQL execution order?
2. WHERE
3. GROUP BY
4. HAVING
5. SELECT
6. DISTINCT
7. ORDER BY
8. LIMIT / OFFSET
Chapter 3 Mastery Quiz 🎯
A table has 5 rows: [100, 200, NULL, 300, NULL]. What does 'SELECT COUNT(*), COUNT(val), SUM(val) FROM t;' return?
Ready for Chapter 4? 🚀
Now that you know how to query and aggregate data within a single table, it's time to unlock the true superpower of Relational Databases:
Next up: Chapter 4 — Joins & Table Relationships (INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN)!