> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8a08bda2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> quantilesGK works similarly to quantileGK but allows us to calculate quantities at different levels simultaneously and returns an array.

# quantilesGK

<h2 id="quantilesGK">
  quantilesGK
</h2>

Introduced in: v23.4.0

Computes multiple [quantiles](https://en.wikipedia.org/wiki/Quantile) of a numeric data sequence at different levels simultaneously using the [Greenwald-Khanna](http://infolab.stanford.edu/~datar/courses/cs361a/papers/quantiles.pdf) algorithm.

This function works similarly with [`quantileGK`](/reference/functions/aggregate-functions/quantileGK) but allows computing multiple quantile levels in a single pass, which is more efficient than calling individual quantile functions.

The Greenwald-Khanna algorithm is an algorithm used to compute quantiles on a stream of data in a highly efficient manner.
It was introduced by Michael Greenwald and Sanjeev Khanna in 2001.
The algorithm is highly efficient, taking only O(log n) space and O(log log n) time per item (where n is the size of the input).
It is also highly accurate, providing approximate quantile values with controllable accuracy.

**Syntax**

```sql theme={null}
quantilesGK(accuracy, level1, level2, ...)(expr)
```

**Parameters**

* `accuracy` — Accuracy of quantiles. Constant positive integer. Larger accuracy value means less error. For example, if the accuracy argument is set to 100, the computed quantiles will have an error no greater than 1% with high probability. There is a trade-off between the accuracy of the computed quantiles and the computational complexity of the algorithm. [`UInt*`](/reference/data-types/int-uint)
* `level` — Levels of quantiles. One or more constant floating-point numbers from 0 to 1. [`Float*`](/reference/data-types/float)

**Arguments**

* `expr` — Expression over the column values resulting in numeric data types, Date or DateTime. [`(U)Int*`](/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)

**Returned value**

Array of quantiles of the specified levels in the same order as the levels were specified. [`Array(Float64)`](/reference/data-types/array) or [`Array(Date)`](/reference/data-types/array) or [`Array(DateTime)`](/reference/data-types/array)

**Examples**

**Computing multiple quantiles with GK algorithm**

```sql title=Query theme={null}
SELECT quantilesGK(1, 0.25, 0.5, 0.75)(number + 1) FROM numbers(1000);
```

```response title=Response theme={null}
┌─quantilesGK(1, 0.25, 0.5, 0.75)(plus(number, 1))─┐
│ [1, 1, 1]                                        │
└──────────────────────────────────────────────────┘
```

**Higher accuracy quantiles**

```sql title=Query theme={null}
SELECT quantilesGK(100, 0.25, 0.5, 0.75)(number + 1) FROM numbers(1000);
```

```response title=Response theme={null}
┌─quantilesGK(100, 0.25, 0.5, 0.75)(plus(number, 1))─┐
│ [251, 498, 741]                                    │
└────────────────────────────────────────────────────┘
```
