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
4

1 回答 1

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中工作。

更新:

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
于 2013-06-25T08:52:26.290 回答