Hive实战之每年最高温度+时间


基表(weather):

时间     温度
2014010114
2014010216
2014010317
2014010410
2014010506
2012010609
2012010732
2012010812
2012010919
2012011023
2001010116
2001010212
2001010310
2001010411
2001010529
2013010619
2013010722
2013010812
2013010929
2013011023

需求:求每一年的最大温度和当时的日期。

实现需求的步骤:

  1,处理基表,把基表转换成年,月,日,温度的形式。

create table tem_weather as select  substr(data,1,4) years ,substr(data,5,2) mon,substr(data,7,2) day,substr(data,9,2) temp from weather ;

  2,创建一个每年的最大温度的视图。

create view tem_view as selelct years as years ,max(temp) as max_temp

from tem_weather group by yeras;

  3,两表内链接查出最大温度的日期。

select * from tem_view a join tem_weather b on a.years=b.yeras and a.max_tmp=b.tmp ;

 

原文地址:https://www.cnblogs.com/songweideboke/p/9849978.html