Skip to content
SQLSimplified
group by

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

Movies (Movies/Actors/Ratings)

Loading database engine...

Step-by-Step Breakdown

  1. AVG(budget_millions) averages budgets within each genre.
  2. ROUND(..., 1) trims the mean to one decimal for readability.
  3. 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:

Employees & Departments

Loading database engine...

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. AVG ignores NULLs; if you need them as zero, wrap with COALESCE(col, 0) first.
  • Forgetting GROUP BY. Without it you get one global average.

Search

Search lessons, functions, examples, and practice problems