Aggregate Functions
Aggregate functions compute a single value across many rows:
COUNT() counts rows, SUM() totals a column,
AVG() averages it, MIN()/MAX()
find the smallest/largest value.
Example: an average score per track
SELECT track, AVG(score) AS avg_score
FROM students
GROUP BY track;
track | avg_score
Frontend | 90.0
Cybersecurity | 78.0
Backend | 85.0
Without GROUP BY, AVG(score) alone would
collapse the entire table into one single average across every
student. Adding GROUP BY track changes that completely: it
computes a separate average for each distinct track value, producing one
row per group instead of one row total — the difference between "what's
the average score overall" and "what's the average score, broken down by
track," which is a genuinely different, much more useful question.
SELECT track, AVG(score) AS avg_score
FROM students
GROUP BY track;
track | avg_score
Frontend | 90.0
Cybersecurity | 78.0
Backend | 85.0