我有一个查询,列出了这些年来的员工评级,但这些年份都列在一列中。我试图让会议多年来拥有自己的分数列,如果他们没有得分则为空。
到目前为止的守则:
SELECT Employee_ID, Meeting_Year, Manager_Readiness_Rating
FROM dbo.v_sc17_TMS_Data_Career_Meeting_Rating
GROUP BY Employee_ID, Meeting_Year, Manager_Readiness_Rating
因此,如果meeting_year是2012,我希望员工列中列出所有2012 Manager_Readiness_Rating。这是一些例子
ID Year Rating
1 2011 11
2 2012 10
3 2010 09
4 2010 03
4 2011 03
我希望它看起来像
ID 2010 2011 2012
1 NULL 11 NULL
2 NULL NULL 1
3 09 NULL NULL
4 03 03 NULL
答案 0 :(得分:2)
SELECT Employee_ID, Meeting_Year, GROUP_CONCAT(Manager_Readiness_Rating)
FROM dbo.v_sc17_TMS_Data_Career_Meeting_Rating
GROUP BY Employee_ID, Meeting_Year
答案 1 :(得分:0)
这被标记为MySQL,但dbo
让我认为它是SQL Server。此查询应适用于任何一个:
SELECT
Employee_ID AS ID,
MAX(CASE WHEN Year = 2010 THEN Rating END) AS R2010,
MAX(CASE WHEN Year = 2011 THEN Rating END) AS R2011,
MAX(CASE WHEN Year = 2012 THEN Rating END) AS R2012
FROM dbo.v_sc17_TMS_Data_Career_Meeting_Rating
GROUP BY Employee_ID
ORDER BY 1