求助,遇到难题了
table:CHECKINOUT 打卡记录表
USERINFO 人员明细表
relation : 通过卡ID连接 From CHECKINOUT A Join USERINFO B On A.USERID=B.USERID
--希前辈修改此SQL语句把2,3倍加班的跟1.5倍加班的分别统计出来 明细及汇总,非常感谢!
目前这条语句已经可以实现统计时间段内所有的加班时间汇总
With Cte([NAME],Wdate,MinTime,MaxTime,WofDay,Hou)
as
( --明细
Select [Name],Convert(VarChar(10),CHECKTIME,121) [Wdate],MIN(CHECKTIME) MinTime,MAX(CHECKTIME) MaxTime,
Datepart(dw,CHECKTIME)-1 WofDay,
Round(Datediff(n,Case When Datepart(dw,CHECKTIME)-1<=6 Then Convert(VarChar(10),
MIN(CHECKTIME),121)+' 17:30:00'
Else
Min(CHECKTIME) End,MAX(CHECKTIME))/60.0,1) Hou
From CHECKINOUT A Join USERINFO B On A.USERID=B.USERID
Where Convert(VarChar(10),CHECKTIME,121) Between '2012-12-01' And '2012-12-31'
Group By [Name],Convert(VarChar(10),CHECKTIME,121),Datepart(dw,CHECKTIME)-1
)
Select [NAME],Right(Wdate,10) Wdate,(Case When Cast(Hou as int)=Cast((Hou+0.5) as int) Then Cast(Hou as int) Else Cast(Hou as int)+0.5 End) Hou
From Cte Where Hou>0 Order By [NAME]
[解决办法]
懒得看代码了,把结果贴出1,2行看看是什么样的。