需求

有如下访客访问次数统计表 t_access_times
59 Hive案例(级联求和)_C
需要输出报表:t_access_times_accumulate
59 Hive案例(级联求和)_C_02

实现步骤

可以用一个hql语句即可实现:

select A.username,A.month,max(A.salary) as salary,sum(B.salary) as accumulate
from 
(select username,month,sum(salary) as salary from t_access_times group by username,month) A 
inner join 
(select username,month,sum(salary) as salary from t_access_times group by username,month) B
on
A.username=B.username
where B.month <= A.month
group by A.username,A.month
order by A.username,A.month;