hive 级联求和 窗口函数

hive 级联求和 窗口函数
Hive窗口函数LAG案例替换级联求和
需求:

原始数据:
A,2015-01,5
A,2015-01,15
B,2015-01,5
A,2015-01,8
B,2015-01,25
A,2015-01,5
A,2015-02,4
A,2015-02,6
B,2015-02,10
B,2015-02,5
1、表的创建和加载:
create table t_access_times(username string,month string,salary int)
row format delimited fields terminated by ‘,’;
load data local inpath ‘’ into table t_access_times
hive 级联求和 窗口函数
2、
求出单个用户的月总金额
create table if not exists c
select username,month,sum(salary) as salary from t_access_times
group by username,month;

使用窗口函数
select username,month,access_time,
(access_time+(lag(access_time,1,0) over (partition by username
order by month asc))) as sum from c;