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

> 计算由 bfloat16 数值组成的样本的近似分位数。

# quantileBFloat16

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

引入版本：v21.7.0

计算由 [bfloat16](https://en.wikipedia.org/wiki/Bfloat16_floating-point_format) 数值组成的样本的近似[分位数](https://en.wikipedia.org/wiki/Quantile)。

`bfloat16` 是一种浮点数据类型，具有 1 个符号位、8 个指数位和 7 个尾数位。
该函数会将输入值转换为 32 位浮点数，并取其最高有效的 16 位。然后计算 `bfloat16` 分位数值，并通过追加零位将结果转换为 64 位浮点数。
该函数是一种快速分位数估算器，最大相对误差为 `0.78125%` (平均相对误差约为 `0.27%`) ，这对应于 `bfloat16` 的 7 位尾数精度。

**语法**

```sql theme={null}
quantileBFloat16[(level)](expr)
```

**别名**: `medianBFloat16`

**参数**

* `level` — 可选。分位数级别。取值范围为 0 到 1。默认值：0.5。[`Float*`](/zh/reference/data-types/float)

**参数**

* `expr` — 包含数值数据的列。[`(U)Int*`](/zh/reference/data-types/int-uint) 或 [`Float*`](/zh/reference/data-types/float)

**返回值**

指定级别的近似分位数值。[`Float64`](/zh/reference/data-types/float)

**示例**

**使用 bfloat16 计算分位数**

```sql title=Query theme={null}
CREATE TABLE example_table (a UInt32, b Float32) ENGINE = Memory;
INSERT INTO example_table VALUES (1, 1.001), (2, 1.002), (3, 1.003), (4, 1.004);

SELECT quantileBFloat16(0.75)(a), quantileBFloat16(0.75)(b) FROM example_table;
```

```response title=Response theme={null}
┌─quantileBFloat16(0.75)(a)─┬─quantileBFloat16(0.75)(b)─┐
│                         3 │                         1 │
└───────────────────────────┴───────────────────────────┘
```

**另请参阅**

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