2015-12-16 37 views
0

我有一個調查表中以下格式如何分組記錄日期明智和Userwise

Date  | Status  | Username 
01-Jan-2015| May Join | John 
01-Jan-2015| Interested | David 
02-Jan-2015| Interested | John 
02-Jan-2015| Interested | David 
02-Jan-2015| Interested | John 

我需要生成相同的用戶羣報道到現在我寫了一個查詢相同。但我需要確定的狀態,向上突破基於這樣

Date  | Username | Interested | May Join 
01-Jan-2015 | John  |  0  | 1 
02-Jan-2015 | John  |  2  | 0 

我的查詢現在同樣的報告:

select Date = convert(date,CONVERT(nvarchar(10),Log,101)), Interested = COUNT(Status), May_Join=(Status) from tblenquiry where convert(date,CONVERT(nvarchar(10),Log,101)) between '01-Jan-15' and '02-jan-15' and User_ID='John' group by convert(date,CONVERT(nvarchar(10),Log,101)) 

請告知並幫助

+1

Gazillion no。這個問題的時間已被回答 –

回答

1

爲此,您可以使用條件彙總:

SELECT 
    Date, 
    Username, 
    Interested = SUM(CASE WHEN Status = 'Interested' THEN 1 ELSE 0 END), 
    [May Join] = SUM(CASE WHEN Status = 'May Join' THEN 1 ELSE 0 END) 
FROM Enquiry 
GROUP BY Date, Username 
+0

非常感謝。 – Prhem