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

> quantilesGKはquantileGKと同様に動作しますが、異なるレベルの分位点を同時に計算し、Arrayを返します。

# quantilesGK

<div id="quantilesGK">
  ## quantilesGK
</div>

導入バージョン: v23.4.0

[Greenwald-Khanna](http://infolab.stanford.edu/~datar/courses/cs361a/papers/quantiles.pdf) アルゴリズムを使用して、数値データの数列に対する複数の[分位点](https://en.wikipedia.org/wiki/Quantile)を、異なるレベルで同時に計算します。

この関数は [`quantileGK`](/ja/reference/functions/aggregate-functions/quantileGK) と同様に動作しますが、複数の分位点レベルを1回の処理で計算できるため、個別の分位点関数を呼び出すよりも効率的です。

Greenwald-Khanna アルゴリズムは、データストリームに対する分位点を非常に効率よく計算するためのアルゴリズムです。
このアルゴリズムは、2001 年に Michael Greenwald と Sanjeev Khanna によって提案されました。
このアルゴリズムは非常に効率的で、各項目あたり O(log n) の空間と O(log log n) の時間しか必要としません (n は入力サイズ) 。
また、精度を制御可能な近似分位点を提供するため、高い精度も備えています。

**構文**

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

**Parameters**

* `accuracy` — 分位点の精度。定数の正の整数です。`accuracy` の値が大きいほど、エラーは小さくなります。たとえば、`accuracy` 引数を 100 に設定すると、計算された分位点の誤差は高い確率で 1% 以下になります。計算される分位点の精度と、アルゴリズムの計算量の間にはトレードオフがあります。[`UInt*`](/ja/reference/data-types/int-uint)
* `level` — 分位点のレベル。0 から 1 までの 1 つ以上の定数の浮動小数点数です。[`Float*`](/ja/reference/data-types/float)

**Arguments**

* `expr` — カラムの値に対する式で、結果は数値 data types、Date、または DateTime になります。[`(U)Int*`](/ja/reference/data-types/int-uint) or [`Float*`](/ja/reference/data-types/float) or [`Decimal*`](/ja/reference/data-types/decimal) or [`Date`](/ja/reference/data-types/date) or [`DateTime`](/ja/reference/data-types/datetime)

**戻り値**

指定したレベルの分位点を、指定されたレベルと同じ順序で格納した Array。[`Array(Float64)`](/ja/reference/data-types/array) or [`Array(Date)`](/ja/reference/data-types/array) or [`Array(DateTime)`](/ja/reference/data-types/array)

**Examples**

**GK アルゴリズムを使用した複数の分位点の計算**

```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]                                        │
└──────────────────────────────────────────────────┘
```

**より高精度の分位点**

```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]                                    │
└────────────────────────────────────────────────────┘
```
