日期:2014-05-17 浏览次数:20379 次
DECLARE @YYDD Varchar(6) SET @YYDD='201201' Select EmpStateName, SUM(Case When InCumbency=1 Then 1 Else 0 End) ZaiZhiCount --在职人数没限制月份 , SUM(Case When CONVERT(Varchar(6), ComeDate, 112) = @YYDD Then 1 Else 0 End) RuZhiCount --入职人数 , CONVERT(Varchar(6),(CASE WHEN SUM(Case When CONVERT(Varchar(6), ComeDate, 112) = @YYDD Then 1 Else 0 End)=0 THEN 0 ELSE (CONVERT(Varchar(6),SUM(Case When CONVERT(Varchar(6), ComeDate, 112) = @YYDD Then 1 Else 0 End) *10000/(SUM(Case When InCumbency=1 Then 1 Else 0 End)*100))) END))+'%' RuZhiRate --入职比例 , SUM(Case When CONVERT(Varchar(6), LeaveDate, 112) = @YYDD Then 1 Else 0 End) LiZhiCount --离职人数 , CONVERT(Varchar(6),(CASE WHEN SUM(Case When CONVERT(Varchar(6), LeaveDate, 112) = @YYDD And InCumbency=0 Then 1 Else 0 End)=0 THEN 0 ELSE (CONVERT(Varchar(6),SUM(Case When CONVERT(Varchar(6), LeaveDate,112) = @YYDD Then 1 Else 0 End) *10000/(SUM(Case When InCumbency=1 Then 1 Else 0 End)*100))) END))+'%' LiZhiRate --离职比例 From PerEmployee Group By EmpStateName /* EmpStateName ZaiZhiCount RuZhiCount RuZhiRate LiZhiCount LiZhiRate 正式工 4663 129 2% 267 5% NULL 249 0 0% 0 0% 试用工 0 0 0% 0 0% 实习生 69 0 0% 0 0% 临时工 12 0 0% 0 0% */
DECLARE @YYDD VARCHAR(6) SET @YYDD = CONVERT(VARCHAR(6), GETDATE(), 112) SELECT EmpStateName, SUM(CASE WHEN InCumbency = 1 THEN 1 ELSE 0 END) ZaiZhiCount --在职人数没限制月份 , SUM(CASE WHEN CONVERT(VARCHAR(6), ComeDate, 112) = @YYDD THEN 1 ELSE 0 END) RuZhiCount --入职人数 , LTRIM(CONVERT(DECIMAL(9,2), ( CASE WHEN SUM(CASE WHEN C