考勤率

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

posted @ 2016-07-12 22:41  change_4_now  阅读(192)  评论(0编辑  收藏  举报