我的表格结构如下:
code | col1 | col2 | col3 |
0001 | c11 | c12 | c13 |
0002 | c21 | c22 | c23 |
0003 | c31 | c32 | c33 |
0004 | c41 | c42 | c43 |
我想把它变成
code | col_to_row | value
0001 | col1 | c11
0001 | col2 | c12
0001 | col3 | c13
0002 | col1 | c21
还有一个。是否有任何内置函数,因为我不喜欢使用下面的查询,因为我的列形式的输入表可以随时间增长
select code,'col1' as col_to_row, col1 as value, from database.table
union all
select code,'col2' as col_to_row, col2 as value, from database.table
union all
select code,'col3' as col_to_row, col3 as value, from database.table
1条答案
按热度按时间wn9m85ua1#
您可以将map函数用于
lateral view explode
作为一种比UNION ALL
s样品o/p