2012-06-27 40 views
0
Select A.SubscriberKey, A.EventDate,B.CreatedDate 
From _Click A 
JOIN _ListSubscribers B 
ON A.SubscriberKey = B.SubscriberKey 
Where B.ListID = '10630' AND B.CreatedDate > (Select DATEADD(day,-180,getdate())) AND A.EventDate IS NULL 
Group By A.SubscriberKey,B.CreatedDate, A.EventDate 

目前需要輸入的SQL語句,正在返回任何內容。我想要返回訂閱者SubscriberKey(這是他們的電子郵件),EventDate(點擊發生的日期)以及他們沒有點擊任何內容時添加的日期(CreatedDate)。任何人都可以幫助我指出正確的方向嗎?感謝大家!得到正確的輸出

+0

什麼定義他們沒有點擊任何東西? – Sammaye

+0

如果用戶沒有點擊任何東西,那麼怎麼會有EventDate? – dbenham

+0

@dbenham這就是我們想要弄清楚的。我們如何顯示誰不點擊任何東西 – realrx7

回答

0

我沒有看到一個GROUP BY的目的,在這種情況下。你沒有做任何聚合。

我相信這會給你找到的結果。

select SubscriberKey, 
     null as EventDate, 
     CreatedDate 
    from _ListSubscribers ls 
where ListID='10630' 
    and CreatedDate > DateAdd(day, -180, getdate()) 
    and not exists(select 1 from _Click c where c.SubscriberKey = B.SubscriberKey) 

以下使用外連接的查詢應該給出相同的結果,它與您的原始查詢更類似。

select ls.SubscriberKey, 
     c.EventDate, 
     ls.CreatedDate 
    from _ListSubscribers ls 
    left outer join _Click c 
    on c.SubscriberKey = ls.SubscriberKey 
where ListID='10630' 
    and CreatedDate > DateAdd(day, -180, getdate()) 
    and c.EventDate is null 
1

嘗試:

SELECT A.SubscriberKey, A.EventDate, B.CreatedDate 
FROM _Click A, _ListSubscribers B 
WHERE A.SubscriberKey(+) = B.SubscriberKey 
AND B.ListID = '10630' 
AND B.CreatedDate > (Select DATEADD(day,-180,getdate())) 
AND nvl(A.EventDate,null) IS NULL 
GROUP BY A.SubscriberKey,B.CreatedDate, A.EventDate 
+0

如果他想要一個「不存在」的條件,那他爲什麼要從表格'A'中選擇項目?和'分組'呢? – alfasin

+0

是啊,我誤解你的查詢,sorrry :( – Sammaye

+0

我們希望多組,將顯示他們是否點擊了超過10倍,2和9,1時,或者根本之間。 – realrx7