我有3张桌子:
表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个广告系列都有不同的广告日期。我尝试查找新订单生成黑白广告系列日期,以将其归因于特定广告系列,因此,如果客户的第一个订单日期属于特定广告系列日期,那么该广告系列中的新客户就是
我的代码是:
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
中选择第一个订单日期,并参考广告系列名称。选择第一个订单日期黑白广告系列发布日期&活动结束日期旁边。
有什么建议吗?