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

> 使用线性插值计算直方图的分位数。

# quantilePrometheusHistogram

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

引入版本：v25.10.0

使用线性插值计算直方图的[分位数](https://en.wikipedia.org/wiki/Quantile)，并考虑每个直方图桶的累积值和上界。

为了得到插值后的值，所有传入的值都会合并到一个数组中，然后按照其对应桶的上界值进行排序。
随后会像 PromQL 的经典直方图 [histogram\_quantile()](https://prometheus.io/docs/prometheus/latest/querying/functions/#histogram_quantile) 函数那样进行分位数插值：找到分位数所在的桶后，使用该桶的下界和上界进行线性插值。

**另请参见**

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

**语法**

```sql theme={null}
quantilePrometheusHistogram(level)(bucket_upper_bound, cumulative_bucket_value)
```

**参数**

* `level` — 可选。分位水平。取值为 0 到 1 之间的常量浮点数。建议将 `level` 的值设在 `[0.01, 0.99]` 范围内。默认值：`0.5`。当 `level=0.5` 时，该函数计算的是[中位数](https://en.wikipedia.org/wiki/Median)。[`Float64`](/zh/reference/data-types/float)

**参数列表**

* `bucket_upper_bound` — 直方图各桶的上界。最大的桶其上界必须为 `+Inf`。[`Float64`](/zh/reference/data-types/float)
* `cumulative_bucket_value` — 直方图各桶的累积值。这些值必须随着桶上界的增大而单调递增。[`(U)Int*`](/zh/reference/data-types/int-uint) 或 [`Float64`](/zh/reference/data-types/float)

**返回值**

返回指定分位水平的分位数。[`Float64`](/zh/reference/data-types/float)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT quantilePrometheusHistogram(bucket_upper_bound, cumulative_bucket_value)
FROM VALUES('bucket_upper_bound Float64, cumulative_bucket_value UInt64', (0, 6), (0.5, 11), (1, 14), (inf, 19));
```

```response title=Response theme={null}
┌─quantilePrometheusHistogram(bucket_upper_bound, cumulative_bucket_value)─┐
│                                                                     0.35 │
└──────────────────────────────────────────────────────────────────────────┘
```

**另请参见**

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