[英]Function to calculate frequencies of the data in postgress
我想按月計算數字變量的均值,標准偏差,百分位數(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);
您可以在文檔中查看聚合功能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.