Aggregate Functions

PostgreSQL includes a number of aggregate functions. Generally, aggregate functions calculate a single return value for an entire range of supplied input values. This behavior operates in contrast to standard functions, which generally return an output value for each supplied input.

AVG

Description

The AVG function returns the average value of the supplied column or expression.

Input
AVG(col | expression) 
Example

Return the average salary from the payroll table:

SELECT AVG(salary) FROM payroll; 

This example shows the use of expressions contained in the AVG function. Specifically, it returns the average amount over $18,000 that employees earn (notice that the criteria provided restricts calculations being performed ...

Get PostgreSQL Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.