[Hive_add_7] Hive 实现最高气温统计


 0. 说明

  Hive 通过 substr() 函数实现最高气温统计


1. Hive 实现最高气温统计

  1.1 思路

  将一行文本加载为 String

  通过 substr() 函数截取年份和温度

  1.2 实现

  1. 创建 temp 表

create table temp(line string);

  2. 加载气温数据到 temp 表中

load data local inpath '/home/centos/files/temp' into table temp;

  3. 编写 SQL 语句

select year, max(temperature) from (select substr(line,16,4) as year, cast(substr(line,88,5) as int) as temperature from temp) a where temperature != 9999 group by year;

  类型转换  cast(temperature as int);


原文地址:https://www.cnblogs.com/share23/p/10224093.html