窗口函数和根据月份时间增量取数
今天跟大家分享一下窗口函数
举个例子:假设当前环境为impala,
drop table if exists dw.stu;
----dw库中的stu表-------------------
create table dw.stu(
fperiod string comment’年月’,
name string comment’姓名’,
age int comment’年龄’,
salary double comment’薪资’,
bonus double comment’奖金‘,
)
partitioned by (dt_month string)
comment’工资表’
row format delimited fields terminated by ‘\001’
stored as parquet;
—以上是建表语句-------------------------------------------------------
–完成增量取数(增加上一个月的数据进来)------------------------
–方法一
insert overwrite table dw.stu partition (dt_month) --此处因为我们用月份分区,所以可以使用insert overwrite,不会覆盖以前的数据,指挥覆盖上月数据,这不影响数据的最终结果。
select
fperiod --年月
,name --姓名
,age --年龄
,salary --薪资
,bonus --奖金
,sum(bonus) as bonus --科目费用
,fperiod as dt_month
from dm.stu_base --数