PostgreSQL 18 reference · Aggregate Functions

PostgreSQL AVG() Function

Return the average of the non-NULL values in a group. Integer input gives a numeric result with full precision.

PostgreSQL 18

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

avg(expression)

Parameters

ParameterDescription
expression A column or expression.

Return value

numeric (or double precision for float input), or NULL.

Examples

Average per group
SELECT department, round(avg(salary)) AS avg_salary
FROM employees
GROUP BY department
ORDER BY avg_salary DESC;

Output

 department  | avg_salary
-------------+------------
 Management  |     250000
 Engineering |     148400
 Sales       |     109333
 Support     |      65000
(4 rows)

Run this on your computer — see “Get Started” for setup.

Full precision
SELECT avg(stock) AS raw_average FROM products;

Output

     raw_average
---------------------
 41.2500000000000000
(1 row)

Run this on your computer — see “Get Started” for setup.

In other languages

Was this page helpful?