Aggregate Function

An aggregate function takes many rows and returns a single summary value. The common ones are COUNT, SUM, AVG, MIN, and MAX.

SQL

Aggregates condense data: instead of listing every order, you can ask for the total, the average, or how many there are. By default they run across all matching rows.

When combined with GROUP BY, an aggregate produces one result per group rather than one overall. Use HAVING to filter those grouped results.

Syntax

SELECT AGG_FUNCTION(column) FROM table_name;

Examples

SQL

SELECT MIN(age) AS youngest,
       MAX(age) AS oldest
FROM users;

Output:

youngest  oldest
--------  ------
18        65

Learn it in a lesson

See also

Back to the Dictionary