Skip to content
ClickHouse Docs

quantileInterpolatedWeighted

Autogenerated from ClickHouse system tables

Introduced in: v23.1.0

Computes quantile of a numeric data sequence using linear interpolation, taking into account the weight of each element.

To get the interpolated value, all the passed values are combined into an array, which are then sorted by their corresponding weights. Quantile interpolation is then performed using the weighted percentile method by building a cumulative distribution based on weights and then a linear interpolation is performed using the weights and the values to compute the quantiles.

When using multiple quantile* functions with different levels in a query, the internal states are not combined (that is, the query works less efficiently than it could). In this case, use the quantiles function.

Syntax

quantileInterpolatedWeighted(level)(expr, weight)

Arguments

Returned value

Quantile of the specified level. For numeric data types the output format matches the input format. (U)Int* or Int128 or UInt128 or Int256 or UInt256 or Float* or Decimal* or Date or DateTime or DateTime64

Examples

Computing interpolated weighted quantile

CREATE TABLE t (
    n Int32,
    val UInt32
) ENGINE = Memory;

INSERT INTO t VALUES (0, 3), (1, 2), (2, 1), (5, 4);

SELECT quantileInterpolatedWeighted(n, val) FROM t;
┌─quantileInterpolatedWeighted(n, val)─┐
│                                    1 │
└──────────────────────────────────────┘