Percentile disc postgresql
xxxxxxxxxx
SELECT PERCENTILE_DISC(percentile) WITHIN GROUP (ORDER BY column_name) FROM table;
To get the median, use a percentile function. The syntax for the percentile functions is different than for other functions you've seen because the data must be ordered to do the computation. It's called ordered set aggregate syntax. The only argument to the function is a number between 0 and 1 corresponding to the percentile you want. You then type "within group", and then, inside parentheses, order by and the name of the column you want to compute the percentile for. PERCENTILE_DISC, or discrete, always returns a value that exists in the column.
xxxxxxxxxx
select
percentile_cont(0.25) within group (order by col_name asc) as q1,
percentile_cont(0.50) within group (order by col_name asc) as median,
percentile_cont(0.75) within group (order by col_name asc) as q3,
percentile_cont(0.95) within group (order by col_name asc) as percentile_95
from table_name