【发布时间】:2017-02-02 01:10:13
【问题描述】:
我有一个要求,我必须在数据库中查询以下条件。
数据库 [Report Pull] 让我们说 2 列
客户 ID ReportDt
我必须找到过去 30 天内没有记录但准确记录(今天 - 30 天)的所有客户。
Select Condition on [Report Pull] PR
and cast(PR.ReportDt as Date) = cast(getdate()-30 as date)
and not exists (
select PR2.*
from [Report Pull] PR2
where 1=1
and cast(PR2.ReportDt as Date) > cast(getdate()-30 as date)
and PR2.CustomerId = PR.CustomerId
)
现在我想吸引这样的客户
cast(getdate()-30 as date) is mod30 = 0
AND at the same time
cast(PR2.ReportDt as Date) > cast(getdate()-30 as date)
Next
cast(getdate()-60 as date) is mod30 = 0
AND at the same time
cast(PR2.ReportDt as Date) > cast(getdate()-60 as date)
that is no report pulled in last 60 days
以此类推,每 30 天一次。这是因为数据库可以有多个报告拉取记录。 我知道这有点令人困惑,但请帮助我。 :)
请注意,我们不能在 SQL 中声明任何变量。数据库是 Salesforce Marketing Cloud 又名 ExactTarget
【问题讨论】:
标签: sql exacttarget