配置单元中是否有sql with子句等价?

bvk5enib  于 2021-06-02  发布在  Hadoop
关注(0)|答案(3)|浏览(351)

在说明书中找不到答案。
所以,我在想:我能在Hive里做这样的事吗?

insert into table my_table
with a as
(
    select *
        from ...
        where ...  
),

b as
(
    select *
        from ...
        where ...  
)
select 
    a.a, 
    a.b, 
    a.c, 
    b.a, 
    b.b, 
    b.c 
from a join b on (a.a=b.a);
gjmwrych

gjmwrych1#

我想你可以一直使用子查询:

insert into table my_table
select 
    a.a, 
    a.b, 
    a.c, 
    b.a, 
    b.b, 
    b.c 
from
(
    select *
        from ...
        where ...  
) a
join 
(
    select *
        from ...
        where ...  
) b
on a.a = b.a;
b09cbbtk

b09cbbtk2#

从版本起,在配置单元中提供 0.13.0 . 此处记录用法。

u2nhd7ah

u2nhd7ah3#

hadoop hive with子句语法和示例借助hive with子句,您可以在同一查询构造中重用查询结果。您还可以使用改进hadoop配置单元查询 WITH 条款。您可以通过将复杂的重复代码移到with子句并引用select语句中创建的逻辑表来简化查询。
带有select语句的hive with子句示例

WITH t1 as (SELECT 1), 
t2 as (SELECT 2),
t3 as (SELECT 3)
SELECT * from t1 
UNION ALL
SELECT * from t2
UNION ALL 
SELECT * from t3;

insert语句中的HIVEWITH子句在向表插入数据时可以使用with子句。例如:

WITH t11 as (SELECT 10),
t12 as (SELECT 20),
t13 as (SELECT 3) 
INSERT INTO t1 
SELECT * from t11 
UNION ALL 
SELECT * from t12 
UNION ALL 
SELECT * from t13;

相关问题