PERCENTILE_CONT
Calculates a percentile, assuming a continuous distribution of values of
PERCENTILE_CONT is available as a window function. See also PERCENTILE_DISC, which returns a percentile equal to a specific column value.
Syntax
PERCENTILE_CONT( <value> ) WITHIN GROUP ( ORDER BY <expression> [ { ASC | DESC } ] )
Parameters
Parameter | Description | Supported input types |
---|---|---|
<value> | Percentile value for the function | DOUBLE PRECISION /REAL literal between 0.0 and 1.0 |
<expression> | Expression used for the ORDER BY clause | NUMERIC or TIMESTAMP |
Return Types
The return type of the function will be the same as the expression type. This function ignores NULL
values.
Example
The example below calculates the median percentile value based on continuous distribution of student grade levels.
SELECT
grade_level,
PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY test_score) AS percentile
FROM
class_test
GROUP BY grade_level;
Returns:
' +-------------+------------+
' | grade_level | percentile |
' +------------+-------------+
' | 9 | 79.5 |
' | 10 | 78 |
' | 11 | 74 |
' | 12 | 93 |
' +-------------+------------+