每日时间sql的最小和最大开始和停止时间

时间:2017-06-19 02:15:22

标签: sql date time

我正在进行一个项目,目的是创建一份报告,让员工每天开始和停止时间,午休时间和总共工作时间。 获得一天记录的最小和最大时间的问题。所以发生的事情是人们有不止一个记录等,离开一个小时左右然后返回。这使报告变得非常混乱。我环顾四周,无法找到解决方案,任何帮助都会很棒。 这是我到目前为止所做的:

 select E.FullName, EL.DateTimeStart, EL.DateTimeStop, E.EmployeeStatusCode, EL.ExtraMinutes,
           Sum(El.ShiftTime /60.0 + (ExtraMinutes / 60.0)) as TotalHoursWorked   
    FROM       dbo.Employee AS E
    INNER JOIN dbo.employeelog AS EL 
    ON         E.EmployeeKey = EL.EmployeeKey   
    where      E.EmployeeStatusCode = 'P' 
    GROUP BY   FullName, EL.DateTimeStart, EL.DateTimeStop, E.EmployeeStatusCode, EL.ExtraMinutes
    having     Sum(El.ShiftTime /60.0 + (ExtraMinutes / 60.0)) > 0
    ORDER BY   FullName

这就是结果

Adam    2017-05-31 07:23:59.593 2017-05-31 07:24:08.923 P   0   0.016666

Adam    2017-06-01 07:00:10.557 2017-06-01 16:03:31.430 P   -30 8.550000

Adam    2017-06-02 07:00:26.877 2017-06-02 12:07:20.137 P   0   5.116666

Adam    2017-06-02 12:49:15.633 2017-06-02 16:13:59.393 P   -30 2.900000

Adam    2017-06-05 07:05:21.670 2017-06-05 16:08:26.250 P   -30 8.550000

Adam    2017-06-06 07:01:42.217 2017-06-06 16:04:58.810 P   -30 8.550000

Adam    2017-06-07 06:59:38.947 2017-06-07 15:16:32.860 P   -30 7.783333

0 个答案:

没有答案