Skip to main content
Skip to main content

quantileExactInclusive

Exactly computes the quantile of a numeric data sequence.

To get exact value, all the passed values ​​are combined into an array, which is then partially sorted. Therefore, the function consumes O(n) memory, where n is a number of values that were passed. However, for a small number of values, the function is very effective.

This function is equivalent to PERCENTILE.INC Excel function, (type R7).

When using multiple quantileExactInclusive 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 quantilesExactInclusive function.

Syntax

quantileExactInclusive(level)(expr)

Arguments

Parameters

  • level — Level of quantile. Optional. Possible values: [0, 1] — bounds included. Default value: 0.5. At level=0.5 the function calculates median. Float.

Returned value

  • Quantile of the specified level.

Type:

  • Float64 for numeric data type input.
  • Date if input values have the Date type.
  • DateTime if input values have the DateTime type.

Example

Query:

CREATE TABLE num AS numbers(1000);

SELECT quantileExactInclusive(0.6)(x) FROM (SELECT number AS x FROM num);

Result:

┌─quantileExactInclusive(0.6)(x)─┐
│                          599.4 │
└────────────────────────────────┘

quantileExactInclusive

Introduced in: v20.1

Similar to quantileExact, this computes the exact quantile of a numeric data sequence.

This function is equivalent to quantileExact but uses the inclusive method for calculating quantiles, as described in the R-7 method.

When using this function, the quantile is calculated such that the interpolation formula for a given quantile p takes the form: x[floor((n-1)*p)] + ((n-1)*p - floor((n-1)*p)) * (x[floor((n-1)*p)+1] - x[floor((n-1)*p)]), where x is the sorted array.

To get the exact value, all the passed values are combined into an array, which is then fully sorted. The sorting algorithm's complexity is O(N·log(N)), where N = std::distance(first, last) comparisons.

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

quantileExactInclusive(level)(expr)

Parameters

  • level — Level of quantile. Constant floating-point number from 0 to 1 (inclusive). We recommend using a level value in the range of [0.01, 0.99]. Float*

Arguments

Returned value

Returns the quantile of the specified level. Float64

Examples

Computing exact inclusive quantile

SELECT quantileExactInclusive(0.25)(number) FROM numbers(5);
┌─quantileExactInclusive(0.25)(number)─┐
│                                    1 │
└──────────────────────────────────────┘

Computing multiple quantile levels

SELECT quantileExactInclusive(0.1)(number), quantileExactInclusive(0.9)(number) FROM numbers(10);
┌─quantileExactInclusive(0.1)(number)─┬─quantileExactInclusive(0.9)(number)─┐
│                                 0.9 │                                 8.1 │
└─────────────────────────────────────┴─────────────────────────────────────┘