Watch the 7.3 Webinar On-Demand
This new release brings updates to Universal Storage, query optimization, and usability that you won’t want to miss.

AVG

Aggregate function. Calculate the average value from a set of numbers. NULL values are ignored. If no values can be averaged, this function returns NULL.

Syntax

AVG ( [DISTINCT] expression )

Arguments

  • DISTINCT: optional keyword. If present, will average the unique values.
  • expression: any numerical expression. This may be a column name, the result of another function, or a math operation

Return Type

A double if the input type is double, otherwise decimal.

Examples

SELECT AVG(table_rows) FROM information_schema.tables;
+-----------------+
| AVG(table_rows) |
+-----------------+
|       1540.0000 |
+-----------------+
1 row in set (2.87 sec)


SELECT AVG(list_price * discount) FROM items;

SELECT AVG(age) FROM employees GROUP BY job_title;