pgsql实现中位数、众数和平均数的计算。
pgsql中不支持median函数,所以只能用percentile_disc实现
代码如下
select
-- 众数
mode() within group ( order by active_days ) as mode_active_days
-- 中位数
,percentile_disc(0.5) within group ( order by active_days ) as median_active_days
-- 平均数
,avg(active_days) as avg_active_days
from info