我想按月计算数字变量的均值、标准差、百分位数 (25,50,75),分类变量的频率以及分类变量和数字变量的 NULL 频率。下面只是样本数据。我有像 20+ 列和 15k+ 记录。我想要执行的功能。
Date id score_n score_p score_s Reason
31-12-2016 1 0.5 6 5.0 energy_drink
31-12-2016 4 6 3 3 soft_drink
31-12-2016 5 3 4 2 energy_drink
最佳答案
思路是:
select date_trunc('month', date) as yyyymm,
avg(score_n) as avg, stddev(score_n),
percentile_cont(0.25) within group (order by score_n),
percentile_cont(0.50) within group (order by score_n),
percentile_cont(0.75) within group (order by score_n)
from t
group by date_trunc('month', date);
您可以查看 documentation 中的聚合函数.
关于sql - 计算postgres中数据频率的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50419997/