Hive典型应用场景之行列转换_小飞鱼_bigdata的博客
在使用Hive处理数据时,经常遇到行列转换的场景,本文将对Hive的行列转换操作做详细的说明。 行转列## 1)多行转多列 假设数据表 row2col: col1 col2 col3 a c 1 a d 2 a e 3 b c 4 b d 5 b e 6 现在要将其转化为: col1 c d e a 1 2 3 b 4 5 6 此时需要使用到max(case … when … then … else 0 end),仅限于转化的字段为数值类型,且为正值的情况。 HQL语句为: select col1, max(case col2 when 'c' then col3 else 0 end) as c, max(case col2 when 'd' then col3 else 0 end) a...阅读全文