← DBMS & SQL learning path
DBMS & SQL · Module 6 of 10

Aggregate functions and GROUP BY

Summarise data with COUNT, SUM, AVG, MIN, MAX and GROUP BY.

📖 Key ideas

  1. COUNT(*) counts rows; SUM, AVG, MIN, MAX summarise columns.
  2. GROUP BY dept makes one summary row per department.
  3. HAVING filters groups (WHERE filters rows before grouping).
  4. Every selected column must be grouped or aggregated.
  5. 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