Skip to content

PERCENTILE_DISC

Given an ordered set of values, this aggregate function returns the discrete percentile value, which is the first input value whose position in the ordering equals or exceeds the specified fraction. See also MEDIAN() and PERCENTILE_CONT.

percentile_disc(fraction) WITHIN GROUP (ORDER BY sort_expression)

Specify a fraction between 0 and 1.

For example:

premdb=# select max(avg_att), min(avg_att), 
percentile_disc(0.2) within group (order by avg_att) from team where avg_att>0;
  max   |  min   | percentile_disc 
--------+--------+-----------------
 75.286 | 11.189 |          24.636
(1 row)
premdb=# select max(avg_att), min(avg_att), 
percentile_disc(0.9) within group (order by avg_att) from team where avg_att>0;
  max   |  min   | percentile_disc 
--------+--------+-----------------
 75.286 | 11.189 |          59.944
(1 row)

Parent topic:Aggregate Functions