Skip to content

percentile_cont ​

Calculates a continuous numeric percentile. When the requested position falls between two values, the result is interpolated between them. NULL values are skipped.

Syntax

text
percentile_cont(fraction) WITHIN GROUP (ORDER BY value [ASC|DESC])
percentile_cont(fraction, value[, descending])

Arguments

  • fraction — A number from zero through one, independent of the group's input rows. It is validated even when the input is empty.
  • value — A numeric expression. NULL values are skipped.
  • descending — An optional constant boolean selecting descending order in the direct form. The default order is ascending.

Use FILTER to select input rows. Array fractions, interval values, and window calls with OVER are not supported.

Returned value

A REAL percentile, or NULL for a NULL fraction or no non-NULL inputs.

Examples

sql
CREATE TABLE readings (value Int32);
INSERT INTO readings VALUES (10), (20), (30), (40), (NULL);
sql
SELECT percentile_cont(0.5) WITHIN GROUP (ORDER BY value)
FROM readings
FORMAT csv;
text
25.0