以下是我的查询,任何人都可以看到任何方法来提高效率,因此它不会超时吗?我正在使用Exacttarget(Salesforce Marketing Cloud)。它有30分钟的超时限制。我尝试过移动的东西,但似乎总是出错。我是SQL的初学者,但上周我已经相当努力了。我的查询如下。谢谢!
SELECT DISTINCT c.Email, c.FName
FROM ENT.Contacts c WITH(NOLOCK)
INNER JOIN ENT.RegistrationData r WITH(NOLOCK)
ON c.Email = r.RegistrationContactEmail
LEFT Join ENT._Subscribers s WITH(NOLOCK)
ON c.Email = s.SubscriberKey
AND s.status NOT IN ('unsubscribed','held')
WHERE
(
(
(
(
r.RegistrationEmailOptStatus = '1' AND
r.RegistrationEventType = 'Wedding' AND
r.RegistrationEventRole IN ('Bride','Other','Bridesmaid','Mother Of the Bride') AND
r.RegistrationCountry IN ('USA') AND
r.RegistrationEventDate < '2014-05-31'
)
OR
(
r.RegistrationEmailOptStatus = '1' AND
r.RegistrationEventType = 'Prom' AND
r.RegistrationEventRole ='Prom' AND
r.RegistrationCountry IN ('USA') AND
r.RegistrationEventDate BETWEEN '2014-01-01' AND '2015-12-31'
)
)
AND
(
(
c.Email IN
(
SELECT DISTINCT
s.SubscriberKey AS Email
FROM
_Open s
WHERE
datediff(mm,s.EventDate, getdate()) <= 3
)
)
OR
(
c.Email IN
(
SELECT DISTINCT
s.SubscriberKey AS Email
FROM
_Click s
WHERE
datediff(mm,s.EventDate, getdate()) <= 3
)
)
)
)
OR
(
r.RegistrationEmailOptStatus = '1' AND
r.RegistrationEventType = 'Wedding' AND
r.RegistrationEventRole IN ('Bride','Other','Bridesmaid','Mother Of the Bride') AND
r.RegistrationCountry IN ('USA') AND
r.RegistrationEventDate BETWEEN '2015-05-01' AND '2015-05-31'
)
)
答案 0 :(得分:1)
我同意Karl的说法,您的主要效果是在引用_Open
和_Click
系统数据视图的子查询中。但是,根据我对ExactTarget(Salesforce Marketing Cloud)的经验,您只能运行'SELECT'语句,并且无法以这种方式声明变量。
我建议在_Open
和_Click
数据视图上运行单独的查询,然后在查询中引用生成的数据扩展名。这可能需要更多步骤。但是,你会发现整体处理时间较短。
对于第一个查询,我会为过去3个月内已打开或点击过的所有人创建数据扩展。然后在第二个查询中,我将使用“IN”语句引用结果数据扩展。这将消除查询中的一个“OR”条件,这可能很昂贵。如果查询仍然表现不佳,我建议在RegistrationData
数据扩展上重写条件逻辑,以避免“OR”条件。
<强>查询1:强>
SELECT DISTINCT s.SubscriberKey AS Email
FROM _Open s WITH(NOLOCK)
WHERE datediff(mm,s.EventDate, getdate()) <= 3
union all
SELECT DISTINCT s.SubscriberKey AS Email
FROM _Click s WITH(NOLOCK)
WHERE datediff(mm,s.EventDate, getdate()) <= 3
<强> QUERY2:强>
SELECT DISTINCT c.Email, c.FName
FROM ENT.Contacts c WITH(NOLOCK)
INNER JOIN ENT.RegistrationData r WITH(NOLOCK)
ON c.Email = r.RegistrationContactEmail
LEFT Join ENT._Subscribers s WITH(NOLOCK)
ON c.Email = s.SubscriberKey
AND s.status NOT IN ('unsubscribed','held')
WHERE
(
(
(
(
r.RegistrationEmailOptStatus = '1' AND
r.RegistrationEventType = 'Wedding' AND
r.RegistrationEventRole IN ('Bride','Other','Bridesmaid','Mother Of the Bride') AND
r.RegistrationCountry IN ('USA') AND
r.RegistrationEventDate < '2014-05-31'
)
OR
(
r.RegistrationEmailOptStatus = '1' AND
r.RegistrationEventType = 'Prom' AND
r.RegistrationEventRole ='Prom' AND
r.RegistrationCountry IN ('USA') AND
r.RegistrationEventDate BETWEEN '2014-01-01' AND '2015-12-31'
)
)
AND
(
c.Email in (
select s.SubscriberKey
from OpenOrClickDE s
where s.SubscriberKey = c.Email
)
)
)
OR
(
r.RegistrationEmailOptStatus = '1' AND
r.RegistrationEventType = 'Wedding' AND
r.RegistrationEventRole IN ('Bride','Other','Bridesmaid','Mother Of the Bride') AND
r.RegistrationCountry IN ('USA') AND
r.RegistrationEventDate BETWEEN '2015-05-01' AND '2015-05-31'
)
)
答案 1 :(得分:0)
我会开枪。可能还有一些小问题,但是对我来说唯一能让查询旋转很长时间的事情就是
c.Email IN
(
SELECT DISTINCT
s.SubscriberKey AS Email
FROM
_Open s
WHERE
datediff(mm,s.EventDate, getdate()) <= 3
)
OR
c.Email IN
(
SELECT DISTINCT
s.SubscriberKey AS Email
FROM
_Click s
WHERE
datediff(mm,s.EventDate, getdate()) <= 3
)
那里有两个问题。首先,你使用IN(SELECT ...)进行日期数学计算,然后使用IN(SELECT ...)几乎肯定效率低下。
要解决第一个问题,请计算单个测试日期并使用它。对于第二个更喜欢用EXISTS检查。
DECLARE @testDate DATE = DATEADD(mm,3,GETDATE())
...
EXISTS(SELECT 1 FROM _Open s WHERE s.EventDate>@testDate AND c.Email = s.SubscriberKey)
OR EXISTS(SELECT 1 FROM _Click s WHERE s.EventDate>@testDate AND c.Email = s.SubscriberKey)
您也可以展开EXISTS并使用连接到_Open和_Click,但这感觉更复杂。
给它一个镜头,让我们知道它是否有帮助。