繁体   English   中英

计算 output 的中位数与过度分区的结果相似

[英]calculating median to output similar results to over partition

我有一张大桌子,这是它的外观片段

name class brand rating
12   d     1     3.8 
22   d     1     3.9
33   a     2     1.1
12   d     1     2.3
12   a     3     3.4
44   b     1     9.8
22   c     2     3.0

我计算了以下评分的平均值

select avg(rating) over(partition by name,class,brand) as avg_rating from df

i'm aware that postgres doesn't have a median function but i would like to calculate for that column and have the output in a similar structure to that of my window function for average

在偶数行的情况下,我想要中间两个数字之间的平均数

要获得中位数,您应该使用 percentile_cont

SELECT percentile_cont(0.5) WITHIN GROUP (ORDER BY rating) FROM df;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM