# Chalk SQL Reference: Aggregate Functions
source: https://docs.chalk.ai/chalksql-docs#section-aggregate-functions

## `approx_count_distinct(x)`
source: https://docs.chalk.ai/chalksql-docs#approx_count_distinct

Returns an approximate number of distinct entries in a df column

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Parameters**

- `x`: `$T`
  The input value. `T` means matching inputs and outputs use the same type.

## `array_agg(x)`
source: https://docs.chalk.ai/chalksql-docs#array_agg

Returns a scalar array of a df column

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Overloads**

#### `array_agg(x)`

**Parameters**

- `x`: `$T`
  The input value. `T` means matching inputs and outputs use the same type.

#### `array_agg(x)`

**Parameters**

- `x`: `$T`
  The input value. `T` means matching inputs and outputs use the same type.

## `count(x)`
source: https://docs.chalk.ai/chalksql-docs#count

Returns the number of entries in a df

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Parameters**

- `x`: `$T`
  The input value. `T` means matching inputs and outputs use the same type.

## `count_distinct(x)`
source: https://docs.chalk.ai/chalksql-docs#count_distinct

Returns the number of distinct entries in a df column

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Parameters**

- `x`: `$T`
  The input value. `T` means matching inputs and outputs use the same type.

## `cpc_sketch(x)`
source: https://docs.chalk.ai/chalksql-docs#cpc_sketch

Returns a CPC sketch of the distinct values in a df column, as binary.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Parameters**

- `x`: `$T`
  The input value. `T` means matching inputs and outputs use the same type.

## `kurtosis(...)`
source: https://docs.chalk.ai/chalksql-docs#kurtosis

Kurtosis of a df column; the bias and fisher flags select the convention.

**Overloads**

#### `kurtosis(x)`

**Parameters**

- `x`: `int8`
  The input value.

#### `kurtosis(arg1, arg2, arg3)`

**Parameters**

- `arg1`: `int8`
- `arg2`: `bool`
- `arg3`: `bool`

#### `kurtosis(x)`

**Parameters**

- `x`: `int16`
  The input value.

#### `kurtosis(arg1, arg2, arg3)`

**Parameters**

- `arg1`: `int16`
- `arg2`: `bool`
- `arg3`: `bool`

#### `kurtosis(x)`

**Parameters**

- `x`: `int32`
  The input value.

#### `kurtosis(arg1, arg2, arg3)`

**Parameters**

- `arg1`: `int32`
- `arg2`: `bool`
- `arg3`: `bool`

#### `kurtosis(x)`

**Parameters**

- `x`: `int64`
  The input value.

#### `kurtosis(arg1, arg2, arg3)`

**Parameters**

- `arg1`: `int64`
- `arg2`: `bool`
- `arg3`: `bool`

#### `kurtosis(x)`

**Parameters**

- `x`: `halffloat`
  The input value.

#### `kurtosis(arg1, arg2, arg3)`

**Parameters**

- `arg1`: `halffloat`
- `arg2`: `bool`
- `arg3`: `bool`

#### `kurtosis(x)`

**Parameters**

- `x`: `float`
  The input value.

#### `kurtosis(arg1, arg2, arg3)`

**Parameters**

- `arg1`: `float`
- `arg2`: `bool`
- `arg3`: `bool`

#### `kurtosis(x)`

**Parameters**

- `x`: `double`
  The input value.

#### `kurtosis(arg1, arg2, arg3)`

**Parameters**

- `arg1`: `double`
- `arg2`: `bool`
- `arg3`: `bool`

## `max(x)`
source: https://docs.chalk.ai/chalksql-docs#max

Returns the max value of a df column

**Overloads**

#### `max(x)`

**Parameters**

- `x`: `int8`
  The input value.

#### `max(x)`

**Parameters**

- `x`: `int16`
  The input value.

#### `max(x)`

**Parameters**

- `x`: `int32`
  The input value.

#### `max(x)`

**Parameters**

- `x`: `int64`
  The input value.

#### `max(x)`

**Parameters**

- `x`: `halffloat`
  The input value.

#### `max(x)`

**Parameters**

- `x`: `float`
  The input value.

#### `max(x)`

**Parameters**

- `x`: `double`
  The input value.

#### `max(x)`

**Parameters**

- `x`: `date32[day]`
  The input value.

#### `max(x)`

**Parameters**

- `x`: `date64[ms]`
  The input value.

#### `max(x)`

**Parameters**

- `x`: `timestamp[us, tz=UTC]`
  The input value.

#### `max(x)`

**Parameters**

- `x`: `duration[us]`
  The input value.

#### `max(x)`

**Parameters**

- `x`: `$Decimal`
  The input value.

## `max_by(x, y)`
source: https://docs.chalk.ai/chalksql-docs#max_by

Return the maximum value of a df column, sorted by the sort column.

**Type parameters.** `V` is the value type of the input map. `S` is the callback state type.

**Parameters**

- `x`: `$V`
  The input value. `V` is the value type of the input map.
- `y`: `$S`
  The second input value. `S` is the callback state type.

## `max_by_n(arg1, arg2, arg3)`
source: https://docs.chalk.ai/chalksql-docs#max_by_n

Return the maximum n values of a df column, sorted by the sort column.

**Type parameters.** `V` is the value type of the input map. `S` is the callback state type.

**Overloads**

#### `max_by_n(arg1, arg2, arg3)`

**Parameters**

- `arg1`: `$V`
  `V` is the value type of the input map.
- `arg2`: `$S`
  `S` is the callback state type.
- `arg3`: `int64`

#### `max_by_n(arg1, arg2, arg3)`

**Parameters**

- `arg1`: `$V`
  `V` is the value type of the input map.
- `arg2`: `$S`
  `S` is the callback state type.
- `arg3`: `int64`

## `mean(x)`
source: https://docs.chalk.ai/chalksql-docs#mean

Returns the mean value of a df column

**Overloads**

#### `mean(x)`

**Parameters**

- `x`: `int8`
  The input value.

#### `mean(x)`

**Parameters**

- `x`: `int16`
  The input value.

#### `mean(x)`

**Parameters**

- `x`: `int32`
  The input value.

#### `mean(x)`

**Parameters**

- `x`: `int64`
  The input value.

#### `mean(x)`

**Parameters**

- `x`: `halffloat`
  The input value.

#### `mean(x)`

**Parameters**

- `x`: `float`
  The input value.

#### `mean(x)`

**Parameters**

- `x`: `double`
  The input value.

## `min(x)`
source: https://docs.chalk.ai/chalksql-docs#min

Returns the min value of a df column

**Overloads**

#### `min(x)`

**Parameters**

- `x`: `int8`
  The input value.

#### `min(x)`

**Parameters**

- `x`: `int16`
  The input value.

#### `min(x)`

**Parameters**

- `x`: `int32`
  The input value.

#### `min(x)`

**Parameters**

- `x`: `int64`
  The input value.

#### `min(x)`

**Parameters**

- `x`: `halffloat`
  The input value.

#### `min(x)`

**Parameters**

- `x`: `float`
  The input value.

#### `min(x)`

**Parameters**

- `x`: `double`
  The input value.

#### `min(x)`

**Parameters**

- `x`: `date32[day]`
  The input value.

#### `min(x)`

**Parameters**

- `x`: `date64[ms]`
  The input value.

#### `min(x)`

**Parameters**

- `x`: `timestamp[us, tz=UTC]`
  The input value.

#### `min(x)`

**Parameters**

- `x`: `duration[us]`
  The input value.

#### `min(x)`

**Parameters**

- `x`: `$Decimal`
  The input value.

## `min_by(x, y)`
source: https://docs.chalk.ai/chalksql-docs#min_by

Return the minimum value of a df column, sorted by the sort column.

**Type parameters.** `V` is the value type of the input map. `S` is the callback state type.

**Parameters**

- `x`: `$V`
  The input value. `V` is the value type of the input map.
- `y`: `$S`
  The second input value. `S` is the callback state type.

## `min_by_n(arg1, arg2, arg3)`
source: https://docs.chalk.ai/chalksql-docs#min_by_n

Return the minimum n values of a df column, sorted by the sort column.

**Type parameters.** `V` is the value type of the input map. `S` is the callback state type.

**Overloads**

#### `min_by_n(arg1, arg2, arg3)`

**Parameters**

- `arg1`: `$V`
  `V` is the value type of the input map.
- `arg2`: `$S`
  `S` is the callback state type.
- `arg3`: `int64`

#### `min_by_n(arg1, arg2, arg3)`

**Parameters**

- `arg1`: `$V`
  `V` is the value type of the input map.
- `arg2`: `$S`
  `S` is the callback state type.
- `arg3`: `int64`

## `mode(x)`
source: https://docs.chalk.ai/chalksql-docs#mode

Returns the mode value of a df column

**Overloads**

#### `mode(x)`

**Parameters**

- `x`: `int8`
  The input value.

#### `mode(x)`

**Parameters**

- `x`: `int16`
  The input value.

#### `mode(x)`

**Parameters**

- `x`: `int32`
  The input value.

#### `mode(x)`

**Parameters**

- `x`: `int64`
  The input value.

#### `mode(x)`

**Parameters**

- `x`: `halffloat`
  The input value.

#### `mode(x)`

**Parameters**

- `x`: `float`
  The input value.

#### `mode(x)`

**Parameters**

- `x`: `double`
  The input value.

#### `mode(x)`

**Parameters**

- `x`: `date32[day]`
  The input value.

#### `mode(x)`

**Parameters**

- `x`: `date64[ms]`
  The input value.

#### `mode(x)`

**Parameters**

- `x`: `timestamp[us, tz=UTC]`
  The input value.

#### `mode(x)`

**Parameters**

- `x`: `duration[us]`
  The input value.

#### `mode(x)`

**Parameters**

- `x`: `string`
  The input value.

#### `mode(x)`

**Parameters**

- `x`: `large_string`
  The input value.

#### `mode(x)`

**Parameters**

- `x`: `binary`
  The input value.

#### `mode(x)`

**Parameters**

- `x`: `large_binary`
  The input value.

#### `mode(x)`

**Parameters**

- `x`: `bool`
  The input value.

#### `mode(x)`

**Parameters**

- `x`: `$Decimal`
  The input value.

## `one(x)`
source: https://docs.chalk.ai/chalksql-docs#one

Returns an arbitrary entry in the group

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Parameters**

- `x`: `$T`
  The input value. `T` means matching inputs and outputs use the same type.

## `set_agg(x)`
source: https://docs.chalk.ai/chalksql-docs#set_agg

Returns a scalar array of distinct values from a df column

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Overloads**

#### `set_agg(x)`

**Parameters**

- `x`: `$T`
  The input value. `T` means matching inputs and outputs use the same type.

#### `set_agg(x)`

**Parameters**

- `x`: `$T`
  The input value. `T` means matching inputs and outputs use the same type.

## `set_union(x)`
source: https://docs.chalk.ai/chalksql-docs#set_union

Returns a scalar array of the distinct union of values from list-typed df column

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Overloads**

#### `set_union(x)`

**Parameters**

- `x`: `list<item: $T>`
  The input value. `T` means matching inputs and outputs use the same type.

#### `set_union(x)`

**Parameters**

- `x`: `large_list<item: $T>`
  The input value. `T` means matching inputs and outputs use the same type.

## `skewness(x, ...)`
source: https://docs.chalk.ai/chalksql-docs#skewness

Skewness of a df column; the bias flag selects population (default) vs sample.

**Overloads**

#### `skewness(x)`

**Parameters**

- `x`: `int8`
  The input value.

#### `skewness(x, y)`

**Parameters**

- `x`: `int8`
  The input value.
- `y`: `bool`
  The second input value.

#### `skewness(x)`

**Parameters**

- `x`: `int16`
  The input value.

#### `skewness(x, y)`

**Parameters**

- `x`: `int16`
  The input value.
- `y`: `bool`
  The second input value.

#### `skewness(x)`

**Parameters**

- `x`: `int32`
  The input value.

#### `skewness(x, y)`

**Parameters**

- `x`: `int32`
  The input value.
- `y`: `bool`
  The second input value.

#### `skewness(x)`

**Parameters**

- `x`: `int64`
  The input value.

#### `skewness(x, y)`

**Parameters**

- `x`: `int64`
  The input value.
- `y`: `bool`
  The second input value.

#### `skewness(x)`

**Parameters**

- `x`: `halffloat`
  The input value.

#### `skewness(x, y)`

**Parameters**

- `x`: `halffloat`
  The input value.
- `y`: `bool`
  The second input value.

#### `skewness(x)`

**Parameters**

- `x`: `float`
  The input value.

#### `skewness(x, y)`

**Parameters**

- `x`: `float`
  The input value.
- `y`: `bool`
  The second input value.

#### `skewness(x)`

**Parameters**

- `x`: `double`
  The input value.

#### `skewness(x, y)`

**Parameters**

- `x`: `double`
  The input value.
- `y`: `bool`
  The second input value.

## `stddev(x)`
source: https://docs.chalk.ai/chalksql-docs#stddev

Returns the sample standard deviation of a df column

**Overloads**

#### `stddev(x)`

**Parameters**

- `x`: `int8`
  The input value.

#### `stddev(x)`

**Parameters**

- `x`: `int16`
  The input value.

#### `stddev(x)`

**Parameters**

- `x`: `int32`
  The input value.

#### `stddev(x)`

**Parameters**

- `x`: `int64`
  The input value.

#### `stddev(x)`

**Parameters**

- `x`: `halffloat`
  The input value.

#### `stddev(x)`

**Parameters**

- `x`: `float`
  The input value.

#### `stddev(x)`

**Parameters**

- `x`: `double`
  The input value.

## `stddev_pop(x)`
source: https://docs.chalk.ai/chalksql-docs#stddev_pop

Returns the population standard deviation of a df column

**Overloads**

#### `stddev_pop(x)`

**Parameters**

- `x`: `int8`
  The input value.

#### `stddev_pop(x)`

**Parameters**

- `x`: `int16`
  The input value.

#### `stddev_pop(x)`

**Parameters**

- `x`: `int32`
  The input value.

#### `stddev_pop(x)`

**Parameters**

- `x`: `int64`
  The input value.

#### `stddev_pop(x)`

**Parameters**

- `x`: `halffloat`
  The input value.

#### `stddev_pop(x)`

**Parameters**

- `x`: `float`
  The input value.

#### `stddev_pop(x)`

**Parameters**

- `x`: `double`
  The input value.

## `sum(x)`
source: https://docs.chalk.ai/chalksql-docs#sum

Returns the sum of a df column

**Overloads**

#### `sum(x)`

**Parameters**

- `x`: `int8`
  The input value.

#### `sum(x)`

**Parameters**

- `x`: `int16`
  The input value.

#### `sum(x)`

**Parameters**

- `x`: `int32`
  The input value.

#### `sum(x)`

**Parameters**

- `x`: `int64`
  The input value.

#### `sum(x)`

**Parameters**

- `x`: `halffloat`
  The input value.

#### `sum(x)`

**Parameters**

- `x`: `float`
  The input value.

#### `sum(x)`

**Parameters**

- `x`: `double`
  The input value.

## `var_pop(x)`
source: https://docs.chalk.ai/chalksql-docs#var_pop

Returns the population variance of a df column

**Overloads**

#### `var_pop(x)`

**Parameters**

- `x`: `int8`
  The input value.

#### `var_pop(x)`

**Parameters**

- `x`: `int16`
  The input value.

#### `var_pop(x)`

**Parameters**

- `x`: `int32`
  The input value.

#### `var_pop(x)`

**Parameters**

- `x`: `int64`
  The input value.

#### `var_pop(x)`

**Parameters**

- `x`: `halffloat`
  The input value.

#### `var_pop(x)`

**Parameters**

- `x`: `float`
  The input value.

#### `var_pop(x)`

**Parameters**

- `x`: `double`
  The input value.

## `variance(x)`
source: https://docs.chalk.ai/chalksql-docs#variance

Returns the sample variance of a df column

**Overloads**

#### `variance(x)`

**Parameters**

- `x`: `int8`
  The input value.

#### `variance(x)`

**Parameters**

- `x`: `int16`
  The input value.

#### `variance(x)`

**Parameters**

- `x`: `int32`
  The input value.

#### `variance(x)`

**Parameters**

- `x`: `int64`
  The input value.

#### `variance(x)`

**Parameters**

- `x`: `halffloat`
  The input value.

#### `variance(x)`

**Parameters**

- `x`: `float`
  The input value.

#### `variance(x)`

**Parameters**

- `x`: `double`
  The input value.
