← DBMS & SQL learning pathDBMS & SQL · Module 6 of 10
Aggregate functions and GROUP BY
Summarise data with COUNT, SUM, AVG, MIN, MAX and GROUP BY.
📖 Key ideas
- COUNT(*) counts rows; SUM, AVG, MIN, MAX summarise columns.
- GROUP BY dept makes one summary row per department.
- HAVING filters groups (WHERE filters rows before grouping).
- Every selected column must be grouped or aggregated.
- Aggregates ignore NULLs except COUNT(*).
💡 Real-life example: GROUP BY is sorting exam papers into piles by class, then counting and averaging each pile.
COUNTCounts rows
AVGAverage of a column
GROUP BYGroups rows for summaries
HAVINGFilters groups