The following are examples of inverse distribution functions. The percentile_cont and percentile_disc functions are not supported as window aggregates.
SELECT grp, percentile_cont(0.4) WITHIN GROUP (ORDER BY sal) AS
fortieth FROM pctest GROUP BY grp;
GRP | FORTIETH
-----+----------
1 | 3000
2 | 980
3 | 1300
(3 rows)
SELECT grp, percentile_disc(0.4) WITHIN GROUP (ORDER BY sal) AS
fortieth FROM pctest GROUP BY grp;
GRP | FORTIETH
-----+----------
1 | 3000
2 | 950
3 | 1250
(3 rows)
The percentile_disc function returns a value for the data set, while percentile_cont returns an interpolated value.
SELECT region, percentile_cont(0.5) WITHIN GROUP(ORDER BY amt) FROM
sales_tbl GROUP BY region;
REGION | PERCENTILE_CONT
-----------+-----------------
Central | 1850
Northeast | 2700
Northwest | 2200
Southwest | 3250
(4 rows)