0

我有一个查询列出了多年来的员工评级,但这些年份都列在一个列中。我试图让会议年份有自己的分数列,如果他们没有分数,则它为空。

到目前为止的代码:

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
4

2 回答 2

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
于 2013-10-15T19:08:55.437 回答
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
于 2013-10-15T19:26:09.323 回答