Link Search Menu Expand Document

PERCENTILE_CONT

Calculates a percentile, assuming a continuous distribution of values of the input expression defined. Results are interpolated, rather than matching any of the specific column values.

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

Return Types

DOUBLE PRECISION 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 |
' +-------------+------------+