0

我有一个查询,我试图从 2012 年和 2013 年提取员工的发展评级:

SELECT Employee_ID, Meeting_Year, Meeting_Readiness_Rating
FROM  dbo.v_sc17_TMS_Data_Career_Meeting_Rating
GROUP BY Employee_ID, Meeting_Year, Meeting_Readiness_Rating

我正在尝试设置案例,以便将 2012 年的评级拉入一列,将 2013 年的评级拉入另一列。我希望它看起来像

Employee ID       2012 Meeting Rating        2013 Meeting Rating

即使他们确实在 2012 年而不是在 2013 年取得了一个,我仍然需要两者的数据,我很难弄清楚这一点。有任何想法吗?

4

3 回答 3

2
SELECT Employee_ID, 
    CASE Meeting_Year WHEN 2012 THEN Meeting_Readiness_Rating ELSE NULL END as [2012 Meeting Rating],
    CASE Meeting_Year WHEN 2013 THEN Meeting_Readiness_Rating ELSE NULL END as [2013 Meeting Rating]
FROM  dbo.v_sc17_TMS_Data_Career_Meeting_Rating
GROUP BY Employee_ID, Meeting_Year, Meeting_Readiness_Rating
于 2013-11-13T15:10:20.413 回答
1
   SELECT Employee_ID, sum(r2012) as '2012 Meeting Rating', sum(r2013) as '2013 Meeting Rating' from 
    (SELECT Employee_ID, 
       CASE Meeting_Year WHEN 2012 THEN Meeting_Readiness_Rating ELSE 0 END as r2012,
        CASE Meeting_Year WHEN 2013 THEN Meeting_Readiness_Rating ELSE 0 END as r2013 FROM  dbo.v_sc17_TMS_Data_Career_Meeting_Rating ) GROUP BY Employee_ID
于 2013-11-13T15:17:23.490 回答
0
SELECT  yr_2012.Employee_ID     
        ,yr_2012.Meeting_Readiness_Rating AS [2012_Meeting_Rating]
        ,yr_2013.Meeting_Readiness_Rating AS [2013_Meeting_Rating]
FROM    dbo.v_sc17_TMS_Data_Career_Meeting_Rating as yr_2012
        CROSS APPLY (
            SELECT  mr.Meeting_Readiness_Rating
            FROM    dbo.v_sc17_TMS_Data_Career_Meeting_Rating as mr
            WHERE   mr.Meeting_Year = '2013' AND
                    yr_2012.Employee_ID = mr.Employee_ID
        ) yr_2013
WHERE   Meeting_Year = '2012' ;
于 2013-11-13T15:14:07.260 回答