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

> 以固定精度同时计算数值序列在不同级别上的多个分位数。

# quantilesTiming

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

引入版本：v1.1.0

以固定精度同时计算数值数据序列在不同级别上的多个[分位数](https://en.wikipedia.org/wiki/Quantile)。

此函数等同于 [`quantileTiming`](/docs/zh/reference/functions/aggregate-functions/quantileTiming)，但它支持在一次遍历中计算多个分位级别，因此比逐个调用分位函数更高效。

该函数的结果是确定性的 (不依赖于查询处理顺序) 。此函数针对描述某些分布的序列进行了优化，例如网页加载时间或后端响应时间。

**准确性**

在以下情况下，计算结果是准确的：

* 值的总数不超过 5670。
* 值的总数超过 5670，但页面加载时间小于 1024 ms。

否则，计算结果会被舍入为最接近的 16 ms 倍数。

<Note>
  在计算页面加载时间分位数时，此函数比 [`quantiles`](/docs/zh/reference/functions/aggregate-functions/quantiles) 更高效且更准确。
</Note>

**语法**

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

**参数**

* `level` — 分位数的级别。一个或多个介于 0 到 1 之间的常量浮点数。建议将 `level` 值设为 `[0.01, 0.99]` 范围内。[`Float*`](/docs/zh/reference/data-types/float)

**Arguments**

* `expr` — 基于列值计算的表达式，结果为数值数据类型、`Date` 或 `DateTime`。如果向函数传入负值，则其行为未定义。如果该值大于 30,000 (即页面加载时间超过 30 秒) ，则视为 30,000。[`(U)Int*`](/docs/zh/reference/data-types/int-uint) or [`Float*`](/docs/zh/reference/data-types/float) or [`Date`](/docs/zh/reference/data-types/date) or [`DateTime`](/docs/zh/reference/data-types/datetime)

**返回值**

按指定级别的顺序返回对应的分位数组。[`Array(Float32)`](/docs/zh/reference/data-types/array)

**示例**

**计算多个时间分位数**

```sql title=Query theme={null}
CREATE TABLE t (response_time UInt32) ENGINE = Memory;
INSERT INTO t VALUES (72), (112), (126), (145), (104), (242), (313), (168), (108);

SELECT quantilesTiming(0.25, 0.5, 0.75)(response_time) FROM t;
```

```response title=Response theme={null}
┌─quantilesTiming(0.25, 0.5, 0.75)(response_time)─┐
│ [108,126,168]                                   │
└─────────────────────────────────────────────────┘
```
