Q9: How do GROUP BY and Aggregate Functions work, and how are NULLs handled?

Difficulty:EasyTopic:Aggregations

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 containing NULL values.
  • COUNT(column_name) counts only non-null values in that column.
  • SUM(), AVG(), MIN(), and MAX() automatically ignore NULL values 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.