SQL AVG
Return the average (mean) of values.
Syntax
AVG(expression)
NULLs are skipped (they do not count as zero).
Example
Query (on the shop database used in the SQL course)
SELECT category, ROUND(AVG(price), 2) AS avg_price FROM products GROUP BY category;
Result
| category | avg_price |
|---|---|
| Books | 53.0 |
| Electronics | 155.0 |
| Furniture | 335.67 |
| Grocery | 22.0 |
| Stationery | 9.75 |
5 rows
Related
Learn it step by step in the free lesson Summarising Data, with exercises that check your queries.