Aggregate AVG
Question
What does AVG() calculate?
Hint
AVG ignores NULL values in the calculation.
Explanation
AVG() calculates the arithmetic mean of non-NULL values in a column. SELECT AVG(price) FROM products returns the average price. AVG ignores NULL values — if 3 of 5 rows have prices, AVG averages those 3. To include NULLs as 0, use AVG(COALESCE(column, 0)). AVG returns a float/decimal, even for integer columns. Use ROUND(AVG(column), 2) to limit decimal places. AVG can be used with GROUP BY for per-group averages. Be aware of integer division: AVG of integers may truncate in some databases.
Related Resources
Related Lessons
- Aggregations
Learn aggregations.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.