用于复制vlookup的配置单元sql查询

8fq7wneg  于 2021-06-26  发布在  Hive
关注(0)|答案(0)|浏览(201)

我有三张table:
表a:

Campaign               Order No          Cust ID
Campaign-Campaign A    Order No-89000    Cust ID-12376;
Campaign-Campaign B    Order No-89003    Cust ID-62376

表b

First Order Date               Cust ID
First Order Date-02-05-2018    Cust_ID-12376;
First Order Date-09-02-2017    Cust_ID-76546

表c:

Campaign                Campaign Launch            Campaign End Date
Campaigns-Campaign A    Launch Date-02-02-2018     End Date-02-28-2018;
Campaigns-Campaign B    Launch Date-09-01-2017     End Date-12-05-2017

它们都有5个活动,所有5个活动都有不同的飞行日期。我试图找到新订单生成的b/w活动日期,以将其归因于特定的活动,因此,如果客户的第一个订单日期落在b/w特定的活动日期,那么这就是该活动中的新客户。
我的代码是:

select
    a.campaign,
    b.first_order_date,
    a.order_no
from
    table_a as a                            
    left join table_b as b on a.cust_id=b.cust_id                           
where
    a.campaign IN
    (
        select
            distinct(campaign)
        from
            table_c
    )
    and
    b.first_order_date between '2017-08-17' AND '2017-09-30'
group by
    a.campaign,
    b.first_order_date,
    a.order_no;

我希望查询从中选择第一个订单日期 Table C 参照市场活动名称。选择第一个订单日期及其旁边的活动启动日期和活动结束日期。
有什么建议吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题