ClickHouse/docs/en/sql-reference/aggregate-functions/reference/quantileApprox.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.8 KiB
Markdown
Raw Normal View History

2023-02-20 02:27:13 +00:00
---
2023-03-07 09:58:30 +00:00
slug: /en/sql-reference/aggregate-functions/reference/quantileApprox
2023-02-20 02:27:13 +00:00
sidebar_position: 204
---
2023-03-07 09:58:30 +00:00
# quantileApprox
2023-02-20 02:27:13 +00:00
2023-03-07 09:54:21 +00:00
Computes the [quantile](https://en.wikipedia.org/wiki/Quantile) of a numeric data sequence using the [Greenwald-Khanna](http://infolab.stanford.edu/~datar/courses/cs361a/papers/quantiles.pdf) algorithm.
2023-02-20 02:27:13 +00:00
**Syntax**
``` sql
2023-03-07 09:58:30 +00:00
quantileApprox(accuracy, level)(expr)
2023-02-20 02:27:13 +00:00
```
2023-03-07 09:58:30 +00:00
Alias: `medianApprox`.
2023-02-20 02:27:13 +00:00
**Arguments**
- `accuracy` — Accuracy of quantile. Constant positive integer. The larger the better.
- `level` — Level of quantile. Optional parameter. Constant floating-point number from 0 to 1. Default value: 0.5. At `level=0.5` the function calculates [median](https://en.wikipedia.org/wiki/Median).
- `expr` — Expression over the column values resulting in numeric [data types](../../../sql-reference/data-types/index.md#data_types), [Date](../../../sql-reference/data-types/date.md) or [DateTime](../../../sql-reference/data-types/datetime.md).
**Returned value**
- Quantile of the specified level and accuracy.
Type:
- [Float64](../../../sql-reference/data-types/float.md) for numeric data type input.
- [Date](../../../sql-reference/data-types/date.md) if input values have the `Date` type.
- [DateTime](../../../sql-reference/data-types/datetime.md) if input values have the `DateTime` type.
**Example**
``` sql
WITH arrayJoin([0, 6, 7, 9, 10]) AS x
2023-03-07 09:58:30 +00:00
SELECT quantileApprox(100, 0.5)(x)
2023-02-20 02:27:13 +00:00
2023-03-07 09:58:30 +00:00
┌─quantileApprox(100, 0.5)(x)─┐
│ 7 │
└──────────────----───────────┘
2023-02-20 02:27:13 +00:00
```
**See Also**
- [median](../../../sql-reference/aggregate-functions/reference/median.md#median)
- [quantiles](../../../sql-reference/aggregate-functions/reference/quantiles.md#quantiles)