> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sdf.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Aggregate Functions

## `array_agg`

Returns an array created from the input x elements.

*Examples:*

```sql examples.sql theme={null}
CREATE TABLE tbl AS VALUES (1), (5), (9);  SELECT array_agg(column1) AS value FROM tbl;
 -- value '[1, 5, 9]'
```

*Supported Signatures*

```sql theme={null}
function array_agg($1) returns array<$1>
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/aggregate.html#array_agg)

## `avg`

Returns the average (arithmetic mean) of all input values.

*Examples:*

```sql examples.sql theme={null}
CREATE TABLE tbl AS VALUES (1), (5), (9); 
 SELECT avg(tbl.column1) AS value FROM tbl; -- value '5.0'
```

*Supported Signatures*

```sql theme={null}
function avg(double) returns double
function avg(decimal(p, s)) returns decimal(p, s)
function avg(real) returns real
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/aggregate.html#avg)

## `count`

Returns the number of input rows.

*Examples:*

```sql examples.sql theme={null}
CREATE TABLE tbl AS VALUES (1), (5), (9); 
 SELECT count(tbl.column1) AS value FROM tbl; -- value '3'
```

*Supported Signatures*

```sql theme={null}
function count() returns bigint
function count($1) returns bigint
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/aggregate.html#count)

## `max`

Returns the maximum value of all input values.

*Examples:*

```sql examples.sql theme={null}
CREATE TABLE tbl AS VALUES (1), (5), (9); 
 SELECT max(tbl.column1) AS value FROM tbl; -- value '9'
```

*Supported Signatures*

```sql theme={null}
function max($1, ...) returns $1
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/aggregate.html#max)

## `min`

Returns the minimum value of all input values.

*Examples:*

```sql examples.sql theme={null}
CREATE TABLE tbl AS VALUES (1), (5), (9); 
 SELECT min(tbl.column1) AS value FROM tbl; -- value '1'
```

*Supported Signatures*

```sql theme={null}
function min($1, ...) returns $1
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/aggregate.html#min)

## `stddev`

This is an alias for stddev\_samp().

*Supported Signatures*

```sql theme={null}
function stddev(bigint) returns double
function stddev(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/aggregate.html#stddev)

## `stddev_pop`

Returns the population standard deviation of all input values.

*Examples:*

```sql examples.sql theme={null}
CREATE TABLE tbl AS VALUES (1), (5), (9);  SELECT stddev_pop(column1) as value from tbl;
 -- value '3.265986323710904'
```

*Supported Signatures*

```sql theme={null}
function stddev_pop(bigint) returns double
function stddev_pop(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/aggregate.html#stddev_pop)

## `stddev_samp`

Returns the sample standard deviation of all input values.

*Examples:*

```sql examples.sql theme={null}
CREATE TABLE tbl AS VALUES (1), (5), (9);  SELECT stddev_samp(column1) as value from tbl;
 -- value '4.0'
```

*Supported Signatures*

```sql theme={null}
function stddev_samp(bigint) returns double
function stddev_samp(double) returns double
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/aggregate.html#stddev_samp)

## `sum`

Returns the sum of all input values.

*Examples:*

```sql examples.sql theme={null}
CREATE TABLE tbl AS VALUES (1), (5), (9); 
 SELECT sum(tbl.column1) AS value FROM tbl; -- value '15'
```

*Supported Signatures*

```sql theme={null}
function sum(bigint) returns bigint
function sum(double) returns double
function sum(decimal(p, s)) returns decimal(38, s)
function sum(real) returns real
```

[🔗 Official Documentation](https://trino.io/docs/current/functions/aggregate.html#sum)
