0

我有一个 SQL 查询,它运行以生成退回的电子邮件地址列表。我遇到的问题是,无论我做什么,当b.SubscriberKey为 0 或不存在时,我都不会取回任何东西。这在b.SubscriberKey大于 0 时工作正常。

我相信这与在可能没有匹配行的表上进行连接有关,但我相信这会导致计数为 0 或 null。当我更改查询以对此进行测试时,我仍然一无所获。

编辑:我正在寻找字符串“No Bounces”以显示查询在我知道实际上没有发生反弹的那一天运行。当前运行时,结果完全空白。

Select 
    case 
       when count(b.SubscriberKey) is not null 
          then b.SubscriberKey 
          else 'No bounces' 
    end as SubscriberKey
from 
    _bounce b
Join 
    _Job j with (nolock) on j.JobID = b.JobID
where 
    convert(date, b.EventDate) = convert(date, dateadd(dd, -1, getdate())) 
    and j.EmailID = 66653 
group by 
    b.SubscriberKey
4

1 回答 1

1

据我了解,您还需要在结果中显示值为 0 或 NULLS 的订阅者键,并且您还声明它可能在该联接表中没有记录。正如您自己所说,在这种情况下,最好的选择是 LEFT Join 而不是 INNER JOIN

Select case when b.SubscriberKey is not null then b.SubscriberKey else 'No bounces' end as SubscriberKey
from _Job j with (nolock)
LEFT Join _bounce b
on j.JobID = b.JobID
where convert(date,b.EventDate)=convert(date,dateadd(dd,-1,getdate())) 
and j.EmailID = 66653 
group by b.SubscriberKey
于 2013-11-20T17:57:54.053 回答