Hive asks for monthly sales and total sales
Monthly sales and total sales
A,01150
A,01200
B,01,1000
B,01800
C,01250
C,01220
B,01,6000
A,02,2000
A,02,3000
B,02,1000
B,02,1500
C,02350
C,02280
A,03350
A,03250
Create table t_store (
Name string comment 'Shop'
Months int comment 'month'
Money int comment 'amount'
)
Row format delimited fields terminated by ","
Load data local inpath "/ root/t_store.txt" into table t_store
Create view v_t_store
As
Select name,months,sum (money) money
From t_store
Group by name,months
Select name,months,money
, sum (money) over (partition by name order by months rows between unbounded preceding and current row) as t_money
From v_t_store
A 1 350 350
A 2 5000 5350
A 3 600 5950
B 1 7800 7800
B 2 2500 10300
C 1 470 470
C 2 630 1100