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;

相关文章:

  • 2021-08-06
  • 2021-12-29
  • 2022-12-23
  • 2019-08-22
  • 2021-07-16
  • 2022-01-28
猜你喜欢
  • 2021-06-22
  • 2020-10-07
  • 2022-12-23
  • 2021-08-15
  • 2021-06-15
相关资源
相似解决方案