AVG
Calculates the average value of a numeric column.
Overview
AVG computes the arithmetic mean of non-NULL values, so its denominator is the count of participating non-NULL rows rather than every row. Combine it with GROUP BY for per-group averages. Result precision depends on the input type and database rules; ROUND can be applied for display.
Basic syntax
SELECT AVG(amount) AS avg_amount FROM orders;
Examples
AVG example
Calculate the average order amount and verify the numerator and denominator from the sample rows.
Sample table
Table:
orders| amount |
|---|
| 1200 |
| 900 |
| 1500 |
| 700 |
Run result
| avg_amount |
|---|
| 1075.0 |
Common issues
Does AVG include NULL rows in its denominator?
No. AVG normally sums and counts only non-NULL values.
Does AVG on integers always return an integer?
No. The return type depends on the database and input type; cast explicitly when precision matters.
How do I calculate an average per group?
Put the grouping column in GROUP BY and apply AVG to the target numeric column.
Tags
Was this explanation clear?
Thanks. This feedback will inform the next content review.