2021-06-26 16:08:23 +00:00
---
2022-08-28 14:53:34 +00:00
slug: /en/sql-reference/aggregate-functions/reference/quantilebfloat16
2022-04-09 13:29:05 +00:00
sidebar_position: 209
2022-08-29 16:19:50 +00:00
title: quantileBFloat16
2021-06-26 16:08:23 +00:00
---
2021-07-29 15:20:55 +00:00
Computes an approximate [quantile ](https://en.wikipedia.org/wiki/Quantile ) of a sample consisting of [bfloat16 ](https://en.wikipedia.org/wiki/Bfloat16_floating-point_format ) numbers. `bfloat16` is a floating-point data type with 1 sign bit, 8 exponent bits and 7 fraction bits.
2021-07-02 20:21:38 +00:00
The function converts input values to 32-bit floats and takes the most significant 16 bits. Then it calculates `bfloat16` quantile value and converts the result to a 64-bit float by appending zero bits.
2021-06-26 16:08:23 +00:00
The function is a fast quantile estimator with a relative error no more than 0.390625%.
**Syntax**
``` sql
quantileBFloat16[(level)](expr)
```
Alias: `medianBFloat16`
**Arguments**
2023-04-19 15:55:29 +00:00
- `expr` — Column with numeric data. [Integer ](../../../sql-reference/data-types/int-uint.md ), [Float ](../../../sql-reference/data-types/float.md ).
2021-06-26 16:08:23 +00:00
**Parameters**
2023-04-19 15:55:29 +00:00
- `level` — Level of quantile. Optional. Possible values are in the range from 0 to 1. Default value: 0.5. [Float ](../../../sql-reference/data-types/float.md ).
2021-06-26 16:08:23 +00:00
**Returned value**
2023-04-19 15:55:29 +00:00
- Approximate quantile of the specified level.
2021-06-26 16:08:23 +00:00
Type: [Float64 ](../../../sql-reference/data-types/float.md#float32-float64 ).
**Example**
Input table has an integer and a float columns:
``` text
┌─a─┬─────b─┐
│ 1 │ 1.001 │
│ 2 │ 1.002 │
│ 3 │ 1.003 │
2021-06-28 19:56:20 +00:00
│ 4 │ 1.004 │
2021-06-26 16:08:23 +00:00
└───┴───────┘
```
2021-07-02 20:18:55 +00:00
Query to calculate 0.75-quantile (third quartile):
2021-06-26 16:08:23 +00:00
``` sql
2021-07-02 20:18:55 +00:00
SELECT quantileBFloat16(0.75)(a), quantileBFloat16(0.75)(b) FROM example_table;
2021-06-26 16:08:23 +00:00
```
Result:
``` text
2021-06-28 19:56:20 +00:00
┌─quantileBFloat16(0.75)(a)─┬─quantileBFloat16(0.75)(b)─┐
│ 3 │ 1 │
└───────────────────────────┴───────────────────────────┘
2021-06-26 16:08:23 +00:00
```
2021-07-02 20:21:38 +00:00
Note that all floating point values in the example are truncated to 1.0 when converting to `bfloat16` .
2021-06-26 20:04:29 +00:00
2022-06-02 10:55:18 +00:00
# quantileBFloat16Weighted
2021-09-22 11:55:14 +00:00
Like `quantileBFloat16` but takes into account the weight of each sequence member.
2021-06-26 20:04:29 +00:00
**See Also**
2023-04-19 15:55:29 +00:00
- [median ](../../../sql-reference/aggregate-functions/reference/median.md#median )
- [quantiles ](../../../sql-reference/aggregate-functions/reference/quantiles.md#quantiles )