员工每周工作时间

时间:2017-03-08 22:31:23

标签: sql sql-server

我需要帮助的是一个查询,以便每周为员工提供一小时的工作时间。我目前对如何报道这件事情一无所知。

我的报告目前只为每个人提供报告,我想要的是能够每周总时数获得特定员工,起初我遇到了麻烦,因为&#34 ; Shifttime"表是以分钟为单位,而不是小时数,所以我得到的是虚假信息,而不是他们的总时间。

SELECT     FullName, 
           DateTimeStart as StartTime, 
           DateTimeStop as FinishTime, 
           FORMAT(ShiftTime /60.0, 'n2') AS HoursWorked, 
           EL.EmployeeKey 
FROM       dbo.Employee AS E
INNER JOIN dbo.employeelog AS EL 
ON         E.EmployeeKey = EL.EmployeeKey 
ORDER BY   FullName;

1 个答案:

答案 0 :(得分:1)

您需要为查询提供输入日期范围

SELECT     FullName, 
           --DateTimeStart as StartTime, 
           --DateTimeStop as FinishTime, 
           --FORMAT(ShiftTime /60.0, 'n2') AS HoursWorked,              
           --EL.EmployeeKey 
           SUM (DATEDIFF(minute, DateTimeStart, DateTimeStop)/60.0) AS HoursWorked
FROM       dbo.Employee AS E
INNER JOIN dbo.employeelog AS EL 
ON         E.EmployeeKey = EL.EmployeeKey 
WHERE      DateTimeStart >= '2017-03-02'
AND        DateTimeStart <  '2017-03-09'
GROUP BY   FullName
ORDER BY   FullName;