我的数据集如下所示(前四列)-
Person Rate Count isImportant Results
A $2 15 true $2
B $1 30 true $1
B $3 10 false (3*10+2.5*25)/(10+25)
B $2.5 25 false (3*10+2.5*25)/(10+25)
D $1.5 20 false $1.5如何通过对列Results和Person进行分组并计算Rate和Count列的加权平均值来生成第五列Rate?
发布于 2020-09-30 06:43:07
您可以使用窗口函数:
select t.*,
sum(rate * count) over(partition by person, isImportant)
/ sum(count) over(partition by person, isImportant) result
from mytable thttps://stackoverflow.com/questions/64128619
复制相似问题