# Aggregate Function

> A SQL tool that turns lots of rows into one number, like a sum.

**Field:** Software Development  
**Category:** Databases  
**Also known as:** SQL Aggregate Function, COUNT, SUM, AVG

## Think of it like

It is like a till at the end of the day. It turns a pile of sales into one total.

## Definition

An aggregate function takes many rows and gives back one value. The common ones are COUNT, SUM, AVG, MIN and MAX. COUNT says how many rows there are, SUM adds them up and AVG gives the average. On its own, it works over every row the query found. With GROUP BY, it gives one answer for each group.

## Example

Emma runs SELECT COUNT(*) FROM orders and sees 1,204. She runs AVG(total) and learns the average order size.

## Example code

```sql
SELECT COUNT(*), AVG(total), MAX(total)
FROM orders;
```

How many orders, the average size and the biggest one, in one line.

## Why it matters

Totals, counts and averages are what most reports show. These functions work them out inside the database, which is fast.

## Common mistake

Thinking AVG counts empty values as zero. These functions skip NULL, so the average only uses rows that have a value.

## Three principles

- **Many in, one out.** A whole set of rows becomes one value.
- **Five common ones.** COUNT, SUM, AVG, MIN, MAX.
- **Per group with GROUP BY.** One answer for each group.

## Related terms

- [GROUP BY Clause](https://learn.benibix.com/term/development/group-by)
- [SELECT Statement](https://learn.benibix.com/term/development/select-statement)
- [Structured Query Language (SQL)](https://learn.benibix.com/term/development/sql)
- [Measure (Analytics)](https://learn.benibix.com/term/data/measure)
- [WHERE Clause](https://learn.benibix.com/term/development/where-clause)

![A table of six orders, each with a city and an amount. An arrow marked WHERE amount > 10 keeps four of the rows and drops two. An arrow marked GROUP BY city puts the four rows into two piles, London and Paris. An arrow marked SUM(amount) turns each pile into one row: London 45 and Paris 30. The last box is the result the SELECT gives back.](https://learn.benibix.com/diagrams/dev-sql-query.svg)

---

Source: https://learn.benibix.com/term/development/aggregate-function
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-16
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
