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;
最后,得到答案,如图所示!
乐于奉献共享,帮助你我他!