Function Reference

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;
avg_price
3231.1785714285714286

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;
family_memberavg_price
11542.5000000000000000
210575.4285714285714286
3505.8000000000000000
4250.0000000000000000
5179.3333333333333333

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.

See also

Where to learn