w3resource logo

postgresql aggregate functions

PostgreSQL AGGREGATE functions

Secondary Nav

What is an aggregate function?

An aggregate function produced a single result for an entire group or table.

Aggregate functions are used to produce summarized results. They operate on sets of rows. They return results based on groups of rows. By default, all rows in a table are treated as one group. The GROUP BY clause of the select statement is used to divide rows into smaller groups.

List of aggregate functions

Name Description
COUNT This function returns the number or rows or non NULL values for a column
SUM This function returns the sum of a selected column.
MAX This function returns the largest value of a specific column.
MIN This function returns the smallest value of a specific column.
AVG This function returns the average value for a specific column.


aggregate_name (expression [,...] [ order_by_clause] )


aggregate_name (ALL expression [,...] [ order_by_clause] )


aggregate_name (DISTINCT expression [,...] [ order_by_clause] )


aggregate_name (* )


Name Description
aggregate_name Name of the aggregate function.
expression Expression is a value or value of the column which itself does not contain any aggregate expression.
order_by_clause The order_by_clause is optional which arranged the result in an order.

Join our Question Answer community to learn and share your programming knowledge.