我有这个结果
ZONE SITE BRAND VALUE
north a a_brand1 10
north a a_brand2 15
north a a_brand3 27
south b b_brand1 17
south b b_brand2 5
south b b_brand3 56
有没有办法按区域和站点分组的总和添加列?像这样:总站点a = 10 + 15 + 27 = 52,总站点b = 17 + 5 + 56 = 78
ZONE SITE BRAND VALUE TOTAL_IN_SITE
north a a_brand1 10 52
north a a_brand2 15 52
north a a_brand3 27 52
south b b_brand1 17 78
south b b_brand2 5 78
south b b_brand3 56 78
感谢。
答案 0 :(得分:2)
使用sum
窗口功能。
select t.*,sum(val) over(partition by zone,site)
from tbl t