AVG() Aggregation With GROUP BY
Compute the average movie budget per genre using AVG() grouped by genre.
Overview
AVG() returns the arithmetic mean of a numeric column. With GROUP BY, it
summarizes a metric per bucket: here, the average production budget for each
movie genre.
The Query
Loading playground environment...
Step-by-Step Breakdown
AVG(budget_millions)averages budgets within each genre.ROUND(..., 1)trims the mean to one decimal for readability.COUNT(*)shows how many movies back each average.
AVG ignores NULLs
Like other aggregates, AVG skips NULL rows rather than treating them as
zero, which keeps the average honest.
Variations
Average salary per department:
Loading playground environment...
Common Mistakes
- Averaging a count instead of a value.
AVG(COUNT(*))is illegal; you can't nest aggregates without a subquery. - Letting NULLs skew intent.
AVGignoresNULLs; if you need them as zero, wrap withCOALESCE(col, 0)first. - Forgetting GROUP BY. Without it you get one global average.
Cite this resource
SQLSimplified. "AVG() Aggregation With GROUP BY Example". Available at: https://sqlsimplified.online/examples/group-by-average