【问题标题】:Identifiy customer with no activity during 6 months and then reactivation of the account识别 6 个月内没有活动的客户,然后重新激活帐户
【发布时间】:2016-07-02 05:14:01
【问题描述】:

我有一张有很多列的表,还有以下几列:

customer_id |交易ID |交易日期

对于每个客户 ID,我们有几笔交易,交易不按时间顺序排列。

我想找到在 6 个月(或更长时间)内没有任何交易的客户,然后在此休眠期之后进行了一次或多次交易。 我希望从 2015 年 1 月开始,所有客户都满足此要求。

几个月以来我一直在使用 Teradata SQL 助手,但我不知道如何处理这个问题。请你帮助我好吗 ?

【问题讨论】:

    标签: teradata


    【解决方案1】:

    这通常使用条件聚合来完成:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-06-25
      • 1970-01-01
      • 2020-12-20
      • 1970-01-01
      • 1970-01-01
      • 2020-04-02
      • 2016-03-11
      • 1970-01-01
      相关资源
      最近更新 更多