数据格式: 2012010732 2012010812 .................... 2015011023 解题思路 1>将数据按日期和温度拆分开 创建表存放原始数据temperature.txt hive> create table if not exists myhive.temper(alldata string); hive> load data local inpath '/home/hadoop/temperature.txt' into table temper; 按年月日 温度拆分子串,日期存的时候按整数或日期格式存比较好,方便后面排序和输出 hive> create table temperature as select substr(alldata,1,4) year,substr(alldata,5,2) month,substr(alldata,7,2) day,substr(alldata,-2,2) tmp from temper;
select int(f.year),collect_set(f.month)[0] month,collect_set(f.day)[0] day,max(f.tmp) from (select year,month,day,tmp from temperature order by year asc,tmp desc) f group by f.year;\n 另外的解题思路: create table temperature1 as select concat_ws( '-', substr(alldata,1,4),substr(alldata,5,2), substr(alldata,7,2) ) as yearT,substr(alldata,-2,2) tmp from temper;