> ## 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.

> 数値データの数列の近似分位点を計算します。

# quantile

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

導入バージョン: v1.1.0

数値データの数列に対する近似 [`quantile`](https://en.wikipedia.org/wiki/Quantile) を計算します。

この関数では、リザーバサイズが最大 8192 の [reservoir sampling](https://en.wikipedia.org/wiki/Reservoir_sampling) と、サンプリング用の乱数生成器を使用します。
結果は決定論的ではありません。
正確な quantile を取得するには、[`quantileExact`](/ja/reference/functions/aggregate-functions/quantileExact#quantileExact) 関数を使用してください。

1 つのクエリ内で異なるレベルを持つ複数の `quantile*` 関数を使用する場合、内部状態は結合されません (つまり、クエリは本来よりも非効率に動作します) 。
この場合は、[`quantiles`](/ja/reference/functions/aggregate-functions/quantiles#quantiles) 関数を使用してください。

空の数値の数列に対しては、`quantile` は NaN を返しますが、`quantile*` の各種バリアントは、種類に応じて NaN またはその数列型のデフォルト値を返します。

**構文**

```sql theme={null}
quantile(level)(expr)
```

**別名**: `median`

**Parameters**

* `level` — 任意。quantile のレベルです。0 から 1 までの定数の浮動小数点数を指定します。`level` の値には `[0.01, 0.99]` の範囲を使用することを推奨します。デフォルト値: 0.5。`level=0.5` の場合、この関数は median を計算します。[`Float`](/ja/reference/data-types/float)

**Arguments**

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

**戻り値**

指定したレベルの近似 quantile 値。[`Float64`](/ja/reference/data-types/float) または [`Date`](/ja/reference/data-types/date) または [`DateTime`](/ja/reference/data-types/datetime)

**Examples**

**quantile の計算**

```sql title=Query theme={null}
CREATE TABLE t (val UInt32) ENGINE = Memory;
INSERT INTO t VALUES (1), (1), (2), (3);

SELECT quantile(val) FROM t;
```

```response title=Response theme={null}
┌─quantile(val)─┐
│           1.5 │
└───────────────┘
```

**関連項目**

* [median](/ja/reference/functions/aggregate-functions/median)
* [quantiles](/ja/reference/functions/aggregate-functions/quantiles)
