Q9: How do GROUP BY and Aggregate Functions work, and how are NULLs handled?
GROUP BY collapses set rows sharing common values into summary groups. Aggregate functions (SUM(), AVG(), COUNT(), MIN(), MAX()) summarize each group.
NULL Handling in Aggregates
COUNT(*)counts all rows, including rows containingNULLvalues.COUNT(column_name)counts only non-null values in that column.SUM(),AVG(),MIN(), andMAX()automatically ignoreNULLvalues during calculation.
Key Takeaways
COUNT(*)includes NULL rows;COUNT(column)ignores NULL entries.- All non-aggregated columns listed in the SELECT clause must be included in the GROUP BY clause.