其他分享
首页 > 其他分享> > 009.hive-hive--lead()上浮、lag()下沉--求同比

009.hive-hive--lead()上浮、lag()下沉--求同比

作者:互联网

hive--lead()上浮、lag()下沉--求同比

 

select 
occur_period
,occur_period_year
,occur_period_month 
,org_name
,people_num
,people_num_2
 -- (今年这个月人数  - 去年这个月人数)/去年这个月人数
,(people_num-people_num_2)/people_num_2  as people_num_t
from 
(
select 
occur_period
,occur_period_year
,occur_period_month 
,people_num
,org_name
-- 去年这个月人数
,lead(people_num,1)over (partition by org_name ,occur_period_month order by occur_period_year desc)  as people_num_2
-- 为得到连续年份
,lead(occur_period_year,1)over (partition by org_name ,occur_period_month order by occur_period_year desc)  as occur_period_year_2
from ioczxk_new.b_st_yz_org_labor
) a where occur_period_year=occur_period_year_2 + 1;

 

标签:lead,people,--,period,hive,num,year,occur
来源: https://www.cnblogs.com/star521/p/15160506.html