七十、Hive——求每一年最大气温的那一天 + 温度

1 、说明
数据格式
2010012325
2014010114
2014010216
2014010317
2014010410
2014010506
2012010609
2012010732
2012010812
2012010919
2012011023
2001010116
2001010212
2001010310
2001010411
2001010529
2013010619
2013010722
2013010812
2013010929
2013011023
2008010105
2008010216
2008010337
2008010414
2008010516
2007010619
2007010712
2007010812
2007010999
2007011023
2010010114
2010010216
2010010317
2010010410
2010010506
2015010649
2015010722
2015010812
2015010999
2015011023
数据解释
2010012325 表示在 2010 01 23 日的气温为 25 度。
解题思路:这道题其实不难,先是建一个气温表temperature,然后导入数据,形成一个有数据的初始表;然后,对数据进行分割,如tmp_weather、tmp_weather2所示,按照年、月、日、温度进行切割,找到自己所需要的数据;最后,把两张表连接查询即可
第一步,创建空气温表temperature
create table if not exists  temperature(
     line string
);

第二步,载入数据,注意文件夹地址,不要照搬
load data local inpath  '/opt/tmp/test/tq.txt' into table  temperature;

第三步,在temperature基础上,按需求切割数据形成两张表tmp_weather、tmp_weather2
//20100123   25
create table  tmp_weather as
select  substr(line,1,4)years,substr(line,5,2) months,substr(line,7,2) days,substr(line,9,2) temp from temperature;

create table  tmp_weather2 as
select  substr(line,1,4)years,max(substr(line,9,2)) max_temp from temperature group by substr(line,1,4);

第4步,把两张表联合查询
select * from  tmp_weather2  t2  
join  tmp_weather t on  t2.years=t.years  and t2.max_temp=t.temp;

最后,得到答案,如图所示!

 乐于奉献共享,帮助你我他!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天地风雷水火山泽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值