SQL
GROUP BY Fundamentals
GROUP BY collapses rows into one row per distinct key. Learn the single rule that governs the select list and how NULLs are grouped.
Grouping rows, aggregating per group, HAVING, and WHERE versus HAVING.
3 notes
GROUP BY collapses rows into one row per distinct key. Learn the single rule that governs the select list and how NULLs are grouped.
HAVING filters groups after aggregation, WHERE filters rows before it. Learn when each applies, why using both is usually correct, and which is faster...
Grouping by several columns, grouping by expressions, and the totals features - ROLLUP, CUBE and GROUPING SETS - that add subtotal rows.