hive中with....as的用法

with...as的用法就相当于join....on的用法
下面展示with怎么用(数据不用管,缩减版)

with
tmp_order as
(
select
sku_id
from detail
),
tmp_payment as
(
select
sku_id,
payment_count
from refund
)
insert overwrite table daycount
select
sku_id,
payment_count,
from
(
select
sku_id,
0 payment_count
from tmp_order
union all
select
sku_id,
payment_count
from tmp_payment
);

解释一下0 payment_count是什么意思
是这张临时表没有 所以用0 payment_count
展示join..on

insert overwrite table daycount
select
    a.sku_id,
    b.payment_count
from
    detail a
join  refund b
on a.sku_id=b.sku_id

这样看显然join…on更简单
总结
表少用join…on
表多用with…as

猜你喜欢

转载自blog.csdn.net/qq_46548855/article/details/107677243