AVG() in MySQL — How It Works

What the MySQL AVG() function does, with an example.

Published October 20, 2026

AVG() returns the average of a numeric column, ignoring NULL values.

How it works

Rows with NULL are excluded from both the sum and the count.

Try it in MySQL

SELECT AVG(price) FROM products
24.9
SELECT category, AVG(price) FROM products GROUP BY category
per category
SELECT ROUND(AVG(rating), 1) FROM reviews
4.3

Practical examples

Example 1

SELECT AVG(price) FROM products;
-- 24.9

Example 2

SELECT category, AVG(price) FROM products GROUP BY category;
-- per category

Example 3

SELECT ROUND(AVG(rating), 1) FROM reviews;
-- 4.3

Use it in a real query

SELECT AVG(price) FROM products;

Common mistakes

  • Forgetting NULLs are skipped (average of non-NULL only).
  • Integer vs DECIMAL precision.
  • Averaging averages across groups.

Key takeaways

  • AVG() in one line: AVG() returns the average of a numeric column, ignoring NULL values.
  • Try queries in a test database first.
  • Check NULL handling and data types.

FAQ

Include NULL as zero?

AVG(IFNULL(col, 0)).

Does AVG() work in other databases?

Most have an equivalent, but names and syntax vary between MySQL, PostgreSQL, SQL Server and SQLite.

More SQL articles