Skip to content
ClickHouse Docs

quantiles

Autogenerated from ClickHouse system tables

Introduced in: v1.1.0

Computes multiple approximate quantiles of a numeric data sequence at different levels simultaneously.

This function applies reservoir sampling with a reservoir size up to 8192 and a random number generator for sampling. The result is non-deterministic.

Using quantiles is more efficient than calling multiple individual quantile functions when you need multiple quantile values, as all quantiles are calculated in a single pass through the data.

Syntax

quantiles(level1, level2, ...)(expr)

Arguments

Returned value

Array of approximate quantiles of the specified levels in the same order as the levels were specified. Numeric arguments produce Float64, while Decimal, Date, DateTime and DateTime64 arguments keep their input format. Array(Float64) or Array(Decimal*) or Array(Date) or Array(DateTime) or Array(DateTime64)

Examples

Computing multiple quantiles efficiently

CREATE TABLE t (val UInt32) ENGINE = Memory;
INSERT INTO t VALUES (1), (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);

SELECT quantiles(0.25, 0.5, 0.75, 0.9)(val) FROM t;
┌─quantiles(0.25, 0.5, 0.75, 0.9)(val)─┐
│ [2.5,5,7.5,9]                        │
└──────────────────────────────────────┘