Hive: Sum over a specified group (HiveQL)

后端 未结 6 849
渐次进展
渐次进展 2021-02-04 14:49

I have a table:

key    product_code    cost
1      UK              20
1      US              10
1      EU              5
2      UK              3
2      EU               


        
6条回答
  •  太阳男子
    2021-02-04 15:05

    You could use BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW to achieve that without a self join.

    Code as below:

    SELECT a, SUM(b) OVER (PARTITION BY c ORDER BY d ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
    FROM T;
    

提交回复
热议问题