【Hive】with子查询与create、insert连用

子查询与create/insert一同使用时,语句写法略有不同。如下。

1 create table

-- 创建表时,create table应该写在所有的with查询之前
create table t_cre as
with t1 as (
    select outid, name
    from t_sel1
),t2 as (
    select outid, name
    from t_sel2
)
select * from t1 full join t2 on bzks.outid = lxs.outid
;

2 insert into

-- 插入数据时,insert (into/overwrite table)应该写在所有with查询之后
with t1 as (
    select outid, name
    from t_sel1
),t2 as (
    select outid, name
    from t_sel2
)
insert overwrite table t_cre
select * from t1 full join t2 on bzks.outid = lxs.outid
;

你可能感兴趣的:(Hive,hive)