Link Search Menu Expand Document

PERCENTILE_DISC

Returns a percentile for an ordered data set. The result is equal to a specific column value, the smallest distributed value that is greater than or equal to the percentile .

PERCENTILE_DISC is available as a window function. See also PERCENTILE_CONT, which calculates an interpolated result, rather than matching any of the specific column values.

Syntax

PERCENTILE_DISC( <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 order by expression type. This function ignores NULL values.

Example

The example below returns the median percentile value based on student grade levels. The percentile value returned is a value from the data set.

SELECT
	grade_level,
	PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY test_score) AS percentile
FROM
	class_test
GROUP BY grade_level;

Returns:

' +-------------+------------+
' | grade_level | percentile | 
' +------------+-------------+
' | 9           |         80 |
' | 10          |         78 |
' | 11          |         75 |
' | 12          |         94 |
' +-------------+------------+