# Aggregate functions

[Read this page in HTML](https://www.scopedb.io/docs/reference/functions/aggregate)

Aggregate functions summarize rows into one value per group. Use them in an `AGGREGATE` clause, optionally preceded by `GROUP BY`.

* Without `GROUP BY`, the query returns one row, even for empty input.
* With `GROUP BY`, the query returns one row per group. Empty input produces no rows.

Each function documents how it handles NULL values and empty input.

Use `WITHIN GROUP ORDER BY` before `AGGREGATE` for order-sensitive functions such as `first`, `last`, and `array_agg`. An `ORDER BY` after `AGGREGATE` sorts the result rows, not the inputs to each aggregate.

## List of functions

* [approx\_quantile](https://www.scopedb.io/docs/reference/functions/aggregate/approx_quantile.md)
* [approx\_count\_distinct](https://www.scopedb.io/docs/reference/functions/aggregate/approx_count_distinct.md)
* [array\_agg](https://www.scopedb.io/docs/reference/functions/aggregate/array_agg.md)
* [avg](https://www.scopedb.io/docs/reference/functions/aggregate/avg.md)
* [count](https://www.scopedb.io/docs/reference/functions/aggregate/count.md)
* [count\_distinct](https://www.scopedb.io/docs/reference/functions/aggregate/count_distinct.md)
* [first, first\_value](https://www.scopedb.io/docs/reference/functions/aggregate/first.md)
* [last, last\_value](https://www.scopedb.io/docs/reference/functions/aggregate/last.md)
* [max](https://www.scopedb.io/docs/reference/functions/aggregate/max.md)
* [max\_by](https://www.scopedb.io/docs/reference/functions/aggregate/max_by.md)
* [min](https://www.scopedb.io/docs/reference/functions/aggregate/min.md)
* [min\_by](https://www.scopedb.io/docs/reference/functions/aggregate/min_by.md)
* [mode](https://www.scopedb.io/docs/reference/functions/aggregate/mode.md)
* [object\_agg](https://www.scopedb.io/docs/reference/functions/aggregate/object_agg.md)
* [quantile](https://www.scopedb.io/docs/reference/functions/aggregate/quantile.md)
* [schema](https://www.scopedb.io/docs/reference/functions/aggregate/schema.md)
* [stddev\_pop](https://www.scopedb.io/docs/reference/functions/aggregate/stddev_pop.md)
* [stddev\_samp](https://www.scopedb.io/docs/reference/functions/aggregate/stddev_samp.md)
* [sum](https://www.scopedb.io/docs/reference/functions/aggregate/sum.md)
* [variance\_pop](https://www.scopedb.io/docs/reference/functions/aggregate/variance_pop.md)
* [variance\_samp](https://www.scopedb.io/docs/reference/functions/aggregate/variance_samp.md)
