Skip to content
SQLSimplified
aggregate

AVG()

Calculates the average (mean) of the values in a numeric column across a group of rows.

Description

AVG is an aggregate function that computes the arithmetic mean of a numeric column: the sum of all the values divided by how many there are. It's commonly used for things like average test scores, average price, or average order size.

Syntax

AVG(column_name)

Parameters

NameDescriptionOptional
expressionThe numeric column or expression to average. NULL values are excluded from both the sum and the count used in the calculation.No

Return Type

AVG returns a DOUBLE, since an average of integers is often not a whole number.

Examples

School (Students/Courses/Grades)

Loading database engine...

School (Students/Courses/Grades)

Loading database engine...

AVG ignores NULLs, it doesn't treat them as zero

If some rows have a NULL score, AVG(score) divides by the number of non-NULL scores, not the total row count. If you actually want NULLs treated as zero, wrap the column in COALESCE(score, 0) first.

Common Mistakes

  • Expecting a NULL score to count as zero. AVG silently skips NULLs, which can make an average look higher than expected if missing scores should really count as 0.
  • Not rounding the result. AVG often returns a long decimal like 86.33333333, which is worth wrapping in ROUND() for readability.
  • Averaging an already-averaged column. Taking AVG of a column that's itself a per-group average (instead of the raw values) gives a mathematically different, often incorrect, result.

See also: SUM, COUNT, MIN.

Search

Search lessons, functions, examples, and practice problems