2013-06-25 157 views
0

我有一個表格,第一格式如下。我想要第二種格式的輸出。幫助表示讚賞。謝謝!生成所需的輸出

UserID IsManagerFeedback Level 
--------------------------------- 
User 1 FALSE    2 
User 2 FALSE    3 
User 5 FALSE    2 
User 1 TRUE     4 
User 3 TRUE     1 
User 4 TRUE     3 
User 5 TRUE     5 




UserID UserFeedback ManagerFeedback 
--------------------------------------- 
User 1 2    4 
User 2 3    NA 
User 3 NA    1 
User 4 NA    3 
User 5 2    5 
+0

很抱歉的格式,因爲我有一個很老的瀏覽器在機器 – Saksham

回答

1
SELECT 
UserID, 
MAX(CASE WHEN IsManagerFeedback = 'FALSE' THEN Level END) AS UserFeedback, 
MAX(CASE WHEN IsManagerFeedback = 'TRUE' THEN Level END) AS ManagerFeedback 
FROM 
Table1 
GROUP BY UserID 

看到它在sqlfiddle帶電作業。

UPDATE:

SELECT 
Year, 
UserID, 
MAX(CASE WHEN IsManagerFeedback = 'FALSE' THEN Level END) AS UserFeedback, 
MAX(CASE WHEN IsManagerFeedback = 'TRUE' THEN Level END) AS ManagerFeedback 
FROM 
Table1 
GROUP BY Year, UserID 
+0

非常感謝tombom! – Saksham

+0

如果我有另一個列以及我需要顯示的年份,可以解決什麼問題? – Saksham

+0

@Saksham查看最新答案。喜歡這個? – fancyPants