PostgreSQL 18 reference · Aggregate Functions

PostgreSQL PERCENTILE_CONT() Function

Return the value at a percentile, interpolating between rows: percentile_cont(0.5) is the median.

PostgreSQL 18 Since 9.4

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

percentile_cont(fraction) WITHIN GROUP (ORDER BY expression)

Parameters

ParameterDescription
fraction From 0 to 1, or an array of fractions.
ORDER BY The values to rank.

Return value

double precision, or an array.

Examples

The median
SELECT percentile_cont(0.5) WITHIN GROUP (ORDER BY salary) AS median_salary FROM employees;

Output

 median_salary
---------------
        127500
(1 row)

Run this on your computer — see “Get Started” for setup.

Several percentiles
SELECT percentile_cont(ARRAY[0.25, 0.5, 0.75]) WITHIN GROUP (ORDER BY price) AS quartiles FROM products;

Output

       quartiles
-----------------------
 {28.74,40.975,67.175}
(1 row)

Run this on your computer — see “Get Started” for setup.

percentile_disc() returns an actual value from the data instead of interpolating.

Version history

VersionChange
PostgreSQL 9.4Added

Was this page helpful?