【发布时间】:2016-07-21 16:47:39
【问题描述】:
所以我创建了一个表,其中包含来自所有客户购买记录的事务表的以下列:
- 月-年,
- 客户 ID、
- 当月的交易次数。
我正在尝试创建一个输出为 1.Month-Year、2.该月流失客户数的表,定义为拥有过去 12 个月内没有交易。 (因此,如果客户在 2014 年 1 月只购买了一次,那么他们会在 2015 年 2 月流失。
如果该人在 2015 年 3 月进行了交易,但直到 2016 年 5 月才进行交易,那么他们在 2016 年 4 月再次流失)。
如果有任何建议,我将不胜感激。
我编写的代码在SQL 中有效,但在Teradata 中无效:
select
month_start_date,
(select 1
from merchantengagement1 t2
where
t2.month_start_date >= t.month_start_date - INTERVAL '1' YEAR and
t2.month_start_date < t.month_start_date and
transactions > 0 and
t.rcvr_ID = t2.rcvr_ID
) then 1 else 0 end) as churnedCustomers
from
merchantengagement1 t
group by month_start_date
【问题讨论】:
标签: teradata