hive之实现列转行,hive列转行


样例: select * from tab1 limit 10; 结果: id  num a  1 a  2 a  3 b  4 b  3 ····· 现在想实现把id一样的数据在一条数据中展现。 结果示例: a  1  2  3 b  4  3   实现方案有多种,在Oracle中LISTAGG函数可以满足,excel中转置可以实现, 数据量不大的话,sql写的复杂些亦可以实现。 在hive中可以参照以下sql来实现: select max(a.id),        concat_ws('\t',collect_set(a.num)) as result from tab1 a 结果: a  1  2  3 b  4  3   仅供参考!

相关内容