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

> quantiles, quantilesExactExclusive, quantilesExactInclusive, quantilesGK

# 分位点 関数

<div id="quantiles">
  ## 分位点
</div>

導入バージョン: v1.1.0

数値データ列に対して、異なるレベルの複数の近似[分位点](https://en.wikipedia.org/wiki/Quantile)を同時に計算します。

この関数では、最大 8192 のリザーバサイズを持つ[リザーバサンプリング](https://en.wikipedia.org/wiki/Reservoir_sampling)と、サンプリング用の乱数生成器を使用します。
結果は非決定論的です。

複数の分位点の値が必要な場合、`quantiles` を使用する方が、個別の `quantile` 関数を複数回呼び出すよりも効率的です。これは、すべての分位点をデータ全体に対する 1 回の走査で計算できるためです。

**構文**

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

**Parameters**

* `level` — 分位点のレベルです。0 から 1 までの定数の浮動小数点数を 1 つ以上指定します。`level` の値には `[0.01, 0.99]` の範囲を使用することを推奨します。[`Float*`](/docs/ja/reference/data-types/float)

**Arguments**

* `expr` — カラムの値に対する式で、結果は数値型、`Date`、`DateTime`、または `DateTime64` である必要があります。[`(U)Int*`](/docs/ja/reference/data-types/int-uint) または [`Int128`](/docs/ja/reference/data-types/int-uint) または [`UInt128`](/docs/ja/reference/data-types/int-uint) または [`Int256`](/docs/ja/reference/data-types/int-uint) または [`UInt256`](/docs/ja/reference/data-types/int-uint) または [`Float*`](/docs/ja/reference/data-types/float) または [`Decimal*`](/docs/ja/reference/data-types/decimal) または [`Date`](/docs/ja/reference/data-types/date) または [`DateTime`](/docs/ja/reference/data-types/datetime) または [`DateTime64`](/docs/ja/reference/data-types/datetime64)

**戻り値**

指定したレベルの近似分位点を、指定したレベルと同じ順序で格納した Array を返します。数値型の引数は `Float64` を生成し、`Decimal`、`Date`、`DateTime`、および `DateTime64` の引数は入力フォーマットを維持します。[`Array(Float64)`](/docs/ja/reference/data-types/array) または [`Array(Decimal*)`](/docs/ja/reference/data-types/array) または [`Array(Date)`](/docs/ja/reference/data-types/array) または [`Array(DateTime)`](/docs/ja/reference/data-types/array) または [`Array(DateTime64)`](/docs/ja/reference/data-types/array)

**Examples**

**複数の分位点を効率的に計算する**

```sql title=Query theme={null}
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;
```

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