59 Hive案例(级联求和)

需求

有如下访客访问次数统计表 t_access_times
59 Hive案例(级联求和)_第1张图片
需要输出报表:t_access_times_accumulate
59 Hive案例(级联求和)_第2张图片

实现步骤

可以用一个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;

你可能感兴趣的:(#,Hive,#,云计算/大数据)