-1

嗨,有人可以帮我吗?

我做了这个查询:

SELECT  DISTINCT(CAMPAIGN),
     count(STATUS)
FROM    
C18_101 INNER JOIN CLIENT_10 ON C18_101.ID = CLIENT_10.ID
WHERE CAMPAIGN in ('Batch 1','Batch 2','Batch 3','Batch 4','Batch 5') AND STATUS = 'Pending' 
GROUP BY  CAMPAIGN,STATUS

结果如下所示:

Batch 2     241

Batch 3     321

Batch 4     575

Batch 5     429

即使没有,我也需要 Batch1 的结果。

4

2 回答 2

3
SELECT  CAMPAIGN,
     count(STATUS)
FROM    C18_101 
LEFT JOIN CLIENT_10 ON C18_101.ID = CLIENT_10.ID AND STATUS = 'Pending' 
WHERE CAMPAIGN in ('Batch 1','Batch 2','Batch 3','Batch 4','Batch 5') 
GROUP BY  CAMPAIGN
于 2013-05-08T13:01:07.913 回答
3
SELECT
     X.CAMPAIGN,
     count(STATUS)
FROM
    (SELECT DISTINCT CAMPAIGN FROM C18_101) X
    LEFT JOIN
    CLIENT_10 C ON X.ID = C.ID AND C.STATUS = 'Pending' 
GROUP BY
    X.CAMPAIGN
  1. 您要么 GROUP BY 要么聚合,而不是两者
  2. 您在 JOIN 之前区分以确保您的计数在每个 CAMPAIGN 中都是正确的
  3. 您真的需要广告系列过滤器吗?如果是,则添加到派生表 X
于 2013-05-08T13:07:47.130 回答