与此问题类似:Is there a way to toggle expanded table formatting mode in PrestoDB cli?。
有没有办法在HIVE中启用扩展表格格式模式?我想在开始大型查询工作之前检查宽表中的一些记录。
从其他问题复制示例:
扩展表格式之前:
select * from sometable;
id | time | humanize_time | value
----+-------+---------------------------------+-------
1 | 09:30 | Early Morning - (9.30 am) | 570
2 | 11:30 | Late Morning - (11.30 am) | 690
3 | 13:30 | Early Afternoon - (1.30pm) | 810
4 | 15:30 | Late Afternoon - (3.30 pm) | 930
(4 rows)
后:
select * from sometable;
-[ RECORD 1 ]-+---------------------------
id | 1
time | 09:30
humanize_time | Early Morning - (9.30 am)
value | 570
-[ RECORD 2 ]-+---------------------------
id | 2
time | 11:30
humanize_time | Late Morning - (11.30 am)
value | 690
-[ RECORD 3 ]-+---------------------------
id | 3
time | 13:30
humanize_time | Early Afternoon - (1.30pm)
value | 810
-[ RECORD 4 ]-+---------------------------
id | 4
time | 15:30
humanize_time | Late Afternoon - (3.30 pm)
value | 930
答案 0 :(得分:1)
您可以使用CROSS JOIN
,CASE
和UNION ALL
的组合。
select
c.col,
case c.col
when 'id' then id
when 'time' then time
when 'humanize_time' then humanize_time
when 'value' then value
end as data
from sometable t
cross join
(
select 'id' as col
union all select 'time' as col
union all select 'humanize_time' as col
union all select 'value' as col
) c ORDER BY id;