SQL Interview: Aggregation, GROUP BY and Subqueries
GROUP BY rules, HAVING versus WHERE, the NULL behaviour of aggregates, and the subquery questions that separate confident answers from vague ones.
Summarising many rows into one value.
8 notes tagged
GROUP BY rules, HAVING versus WHERE, the NULL behaviour of aggregates, and the subquery questions that separate confident answers from vague ones.
Turning rows into columns and back again with portable SQL. Conditional aggregation, the PIVOT operator where it exists, and unpivoting with UNION ALL...
Window functions compute across related rows without collapsing them. Learn the OVER clause, PARTITION BY, window ORDER BY, and how they differ from G...
Grouping by several columns, grouping by expressions, and the totals features - ROLLUP, CUBE and GROUPING SETS - that add subtotal rows.
HAVING filters groups after aggregation, WHERE filters rows before it. Learn when each applies, why using both is usually correct, and which is faster...
GROUP BY collapses rows into one row per distinct key. Learn the single rule that governs the select list and how NULLs are grouped.
Aggregating an expression rather than a column: weighted totals, conditional counts and the difference between counting rows and counting facts.
The five aggregate functions that collapse many rows into one value, the three forms of COUNT, and what each one does with NULL.