AVG
Returns the arithmetic mean of the expression values in a group of rows.
PostgreSQL 17.5
AVG([DISTINCT] expression)Parameters
- DISTINCTkeywordoptional
- Use each value only once
- expressionnumeric
- Numeric expression to average
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.5
SELECT AVG(unit_price) AS avg_price
FROM Payments;Average price per family member
PostgreSQL 17.5
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.