首页 > 其他 > 详细

Hive求每一年最大气温的那一天 + 温度

时间:2018-11-23 16:03:21      阅读:251      评论:0      收藏:0      [点我收藏+]
2014010216
2014010410
2012010609
2012010812
2012011023
2001010212
2001010411
2013010619
2013010812
2013011023
2008010216
2008010414
2007010619
2007010812
2007011023
2010010216
2010010410
2015010649
2015010812
2015011023

create table t_wendu_line(
line string
);
load data local inpath ‘/root/wendu.txt‘ into table t_wendu_line;
求每一年最大气温的那一天 + 温度
临时数据存放在视图中
create view v_temperature_data
as
select substr(line,1,4) as year,
from_unixtime(unix_timestamp(substr(line,1,8),‘yyyymmdd‘),‘yyyy-mm-dd‘) tdate
,cast(substr(line,9,2) as smallint) as temperature_num
from t_wendu_line;

select year,tdate,temperature_num
from (
select year,tdate,temperature_num,
row_number() over(partition by year order by temperature_num desc ) as rn
,rank() over(partition by year order by temperature_num desc ) as rn1
,dense_rank() over(partition by year order by temperature_num desc ) as rn2
from v_temperature_data
) tmp
where tmp.rn = 1;

2001 2001-01-02 12
2007 2007-01-10 23
2008 2008-01-02 16
2010 2010-01-02 16
2012 2012-01-10 23
2013 2013-01-10 23
2014 2014-01-02 16
2015 2015-01-06 49

Hive求每一年最大气温的那一天 + 温度

原文:http://blog.51cto.com/6000734/2321085

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!