AVG
Returns the arithmetic mean of the expression values in a group of rows.
PostgreSQL 17.9
AVG([DISTINCT] expression)- [ ]optional part
- DISTINCT
- Use each value only onceKeywordOptional
- expression
- Numeric expression to averagenumeric
Return value
A number: numeric for integers and numeric, double precision for floating-point numbers; NULLs are ignored, NULL for an empty set
Examples
Average price in payments
PostgreSQL 17.9
SELECT AVG(unit_price) AS avg_price
FROM Payments;Average price per family member
PostgreSQL 17.9
SELECT family_member,
AVG(unit_price) AS avg_price
FROM Payments
GROUP BY family_member
ORDER BY family_member;Details
Rows with NULL are left out of both the sum and the count: to treat them as zeros, use AVG(COALESCE(x, 0)). For integers the result is numeric with many decimal places, so it is usually rounded with ROUND.