Hive: Sum over a specified group (HiveQL)

后端 未结 6 833
渐次进展
渐次进展 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:00

    Similar to @VB_ answer, use the BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING statement.

    The HiveQL query is therefore:

    SELECT key, product_code,
    SUM(costs) OVER (PARTITION BY key ORDER BY key ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
    FROM test;
    

提交回复
热议问题