确定 6 个月内没有 activity 的客户,然后重新激活帐户
Identifiy customer with no activity during 6 months and then reactivation of the account
我有一个 table 有很多列和以下列:
customer_id | Transaction_ID |交易日期
对于每个客户 ID,我们有几笔交易,这些交易没有按时间顺序排列。
我想找到在 6 个月(或更长时间)内没有任何交易,然后在此休眠期之后进行了一次或多次交易的客户。
我希望所有客户从 2015 年 1 月开始满足此要求。
几个月以来我一直在使用 Teradata SQL 助手,但我不确定如何处理它。请你帮助我好吗 ?
这通常使用条件聚合来完成:
select customer_id
from tab
group by customer_id
-- transactions before start
having sum(case when Transaction_Date < date '2015-01-01' then 1 else 0 end) > 0
-- transactions after end
and sum(case when Transaction_Date > date '2015-06-30' then 1 else 0 end) > 0
-- no transactions between start and end
and sum(case when Transaction_Date between date '2015-01-01' and date '2015-06-30' then 1 else 0 end) = 0
我有一个 table 有很多列和以下列:
customer_id | Transaction_ID |交易日期
对于每个客户 ID,我们有几笔交易,这些交易没有按时间顺序排列。
我想找到在 6 个月(或更长时间)内没有任何交易,然后在此休眠期之后进行了一次或多次交易的客户。 我希望所有客户从 2015 年 1 月开始满足此要求。
几个月以来我一直在使用 Teradata SQL 助手,但我不确定如何处理它。请你帮助我好吗 ?
这通常使用条件聚合来完成:
select customer_id
from tab
group by customer_id
-- transactions before start
having sum(case when Transaction_Date < date '2015-01-01' then 1 else 0 end) > 0
-- transactions after end
and sum(case when Transaction_Date > date '2015-06-30' then 1 else 0 end) > 0
-- no transactions between start and end
and sum(case when Transaction_Date between date '2015-01-01' and date '2015-06-30' then 1 else 0 end) = 0