码迷,mamicode.com
首页 > 其他好文 > 详细

考勤率

时间:2016-07-12 22:58:02      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

SELECT  cast(cast( SUM(SumTime)*100 as float)/SUM(TotalTime) as decimal(10,2))  FROM (
SELECT ROW_NUMBER() OVER(ORDER BY CamId) AS RowNum,CamId,CamName,CamDateStartUse,
                            (SELECT DevTypeName FROM dbo.Com_DevType WHERE DevTypeId=CamTypeId) AS DevTypeName
                            ,SUM(ISNULL(CamTimer_Unit,0)) AS SumTime,
                            ISNULL(DATEDIFF(MINUTE,CASE WHEN ‘2016-05-01‘<DATEADD(DAY,1,CONVERT(varchar(100), ISNULL(CamDateStartUse,‘1900-1-1‘), 23))
                            THEN DATEADD(DAY,1,CONVERT(varchar(100), ISNULL(CamDateStartUse,‘1900-1-1‘), 23)) ELSE ‘2016-05-01‘ END,CASE WHEN ‘2016-05-28‘>GETDATE() THEN DATEADD(HOUR,1,GETDATE()) ELSE ‘2016-05-28‘ END),0)
                             AS TotalTime
                            FROM dbo.Dat_Camera LEFT JOIN dbo.Dat_CameraTimer
                            ON CamTimer_CamId=CamId
                            AND CamTimer_CreateTime>=CASE WHEN ‘2016-05-01‘<DATEADD(DAY,1,CONVERT(varchar(100), CamDateStartUse, 23))
                            THEN DATEADD(DAY,1,CONVERT(varchar(100), CamDateStartUse, 23)) ELSE ‘2016-05-01‘ END AND CamTimer_CreateTime<=‘2016-05-28‘
                            WHERE CamProjId=‘11980‘
                            AND (CamFlowState=15 or CamFlowState=16)
                            AND CamTypeId IN(SELECT DevTypeId FROM dbo.Com_DevType WHERE DevCategory=1)
                            GROUP BY CamId,CamName,CamTypeId,CamDateStartUse) AS t

考勤率

标签:

原文地址:http://www.cnblogs.com/change4now/p/5665190.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!