# quantiles (/docs/reference/sql/aggregate-functions/quantiles)



This page describes the RawTree engine binary used to generate this reference. It does not define Query API support. Descriptions retain upstream ClickHouse terminology. See [SQL interface scope](/docs/reference/clickhouse-compatibility#service-interfaces).

Computes multiple approximate [quantiles](https://en.wikipedia.org/wiki/Quantile) of a numeric data sequence at different levels simultaneously.

This function applies [reservoir sampling](https://en.wikipedia.org/wiki/Reservoir_sampling) with a reservoir size up to 8192 and a random number generator for sampling.
The result is non-deterministic.

Using `quantiles` is more efficient than calling multiple individual `quantile` functions when you need multiple quantile values, as all quantiles are calculated in a single pass through the data.

**Syntax**

```sql
quantiles(level1, level2, ...)(expr)
```

**Parameters**

* `level` — Levels of quantiles. One or more constant floating-point numbers from 0 to 1. We recommend using `level` values in the range of `[0.01, 0.99]`. [`Float*`](/reference/data-types/float)

**Arguments**

* `expr` — Expression over the column values resulting in numeric data types, `Date`, `DateTime` or `DateTime64`. [`(U)Int*`](/reference/data-types/int-uint) or [`Int128`](/reference/data-types/int-uint) or [`UInt128`](/reference/data-types/int-uint) or [`Int256`](/reference/data-types/int-uint) or [`UInt256`](/reference/data-types/int-uint) or [`Float*`](/reference/data-types/float) or [`Decimal*`](/reference/data-types/decimal) or [`Date`](/reference/data-types/date) or [`DateTime`](/reference/data-types/datetime) or [`DateTime64`](/reference/data-types/datetime64)

**Returned value**

Array of approximate quantiles of the specified levels in the same order as the levels were specified. Numeric arguments produce `Float64`, while `Decimal`, `Date`, `DateTime` and `DateTime64` arguments keep their input format. [`Array(Float64)`](/reference/data-types/array) or [`Array(Decimal*)`](/reference/data-types/array) or [`Array(Date)`](/reference/data-types/array) or [`Array(DateTime)`](/reference/data-types/array) or [`Array(DateTime64)`](/reference/data-types/array)

**Examples**

**Computing multiple quantiles efficiently**

```sql title=Query
CREATE TABLE t (val UInt32) ENGINE = Memory;
INSERT INTO t VALUES (1), (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);

SELECT quantiles(0.25, 0.5, 0.75, 0.9)(val) FROM t;
```

```text title=Response
┌─quantiles(0.25, 0.5, 0.75, 0.9)(val)─┐
│ [3, 5.5, 8, 9.5]                     │
└──────────────────────────────────────┘
```

*Introduced in version 1.1.0.*
