gpt4 book ai didi

sql-server - Hive CTE,我可以将值查询为表吗?

转载 作者:可可西里 更新时间:2023-11-01 15:10:26 25 4
gpt4 key购买 nike

我正在尝试创建我想稍后在我的数据拉取中使用的查询中维度表。在 MS SQL 中,我可以摆脱使用值作为表的 CTE:

with tbl_test_values as (select * from (
VALUES
('Number','1','One'),
('Number','5','Five'),
('Letter','A','First Letter'),
('Human','Bob','Dude')
) as
TestValues --equivalent of table name
(Name, Value, Descript) --essentially field names
)
select * from actual_data_table f
left outer join tbl_test_values d on f.Name=d.Name

有没有办法在 Hive 中复制上述 CTE“tbl_test_values”,即查询自定义值集作为表?

谢谢

最佳答案

1.

内联

with    tbl_test_values as
(
select inline
(
array
(
struct ('Number','1','One')
,struct ('Number','5','Five')
,struct ('Letter','A','First Letter')
,struct ('Human','Bob','Dude')
)
) as (Name, Value, Descript)
)

select * from tbl_test_values
;

+--------+-------+--------------+
| name | value | descript |
+--------+-------+--------------+
| Number | 1 | One |
| Number | 5 | Five |
| Letter | A | First Letter |
| Human | Bob | Dude |
+--------+-------+--------------+

2.

堆栈

with    tbl_test_values as
(
select stack
(
4
,'Number' ,'1' ,'One'
,'Number' ,'5' ,'Five'
,'Letter' ,'A' ,'First Letter'
,'Human' ,'Bob' ,'Dude'
) as (Name, Value, Descript)
)

select * from tbl_test_values
;

+--------+-------+--------------+
| name | value | descript |
+--------+-------+--------------+
| Number | 1 | One |
| Number | 5 | Five |
| Letter | A | First Letter |
| Human | Bob | Dude |
+--------+-------+--------------+

关于sql-server - Hive CTE,我可以将值查询为表吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43243669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com