我有一个要求,我必须在数据库中查询以下条件。
数据库 [Report Pull] 让我们说 2 列
CustomerID 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