数仓-ADS-各地区订单统计

lateral view

    -- lateral view首先为原始表的每行调用UDTF(explode,split),UDTF会把一行拆分成一或者多行,lateral view再把结果组合,产生一个支持别名表的虚拟表
    -- 主要解决在select使用UDTF做查询的过程中查询只能包含单个UDTF,不能包含其它字段以及多个UDTF的情况

insert overwrite table ads_order_by_province
select * from ads_order_by_province
union
select
    '2021-06-14' dt,
    t1.recent_days,
    t1.province_id,
    t2.province_name,
    t2.area_code,
    t2.iso_code,
    t2.iso_3166_2,
    t1.order_count,
    t1.order_amount
from
(
    select
        recent_days,
        province_id,
        -- 使用case when,根据天数取出dwt_area_topic中对应字段
        case
            when recent_days=1 then order_last_1d_count
            when recent_days=7 then order_last_7d_count
            when recent_days=30 then order_last_30d_count
        end order_count,
        case
            when recent_days=1 then order_last_1d_final_amount
            when recent_days=7 then order_last_7d_final_amount
            when recent_days=30 then order_last_30d_final_amount
        end order_amount
    from dwt_area_topic
    lateral view explode(Array(1,7,30)) tmp as recent_days
    where dt='2021-06-14'
)t1
left join
(
    select
        id,
        province_name,
        area_code,
        iso_code,
        iso_3166_2
    from dim_base_province
)t2
on t1.province_id=t2.id;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值