基本上我想知道商店开门和关门时有多少员工,详细信息如下
EmployeeID | IN and OUT Time | Type | InOut ID | Comments |
---------- | ----------------------- |------------| ---------|-------------|
12961 2017-04-24 08:07:00.000 Punch In 1 Store Open
12680 2017-04-24 08:07:00.000 Punch In 2
12662 2017-04-24 08:07:00.000 Punch In 3
12683 2017-04-24 08:27:00.000 Punch In 4
12864 2017-04-24 08:42:00.000 Punch In 5
12681 2017-04-24 10:03:00.000 Punch In 6
-1 2017-04-24 13:33:00.000 Punch In 7
12662 2017-04-24 18:00:00.000 Punch Out 8
12683 2017-04-24 18:00:00.000 Punch Out 9
12864 2017-04-24 18:35:00.000 Punch Out 10
12681 2017-04-24 22:00:00.000 Punch Out 11
12960 2017-04-24 22:00:00.000 Punch Out 12
12959 2017-04-24 22:00:00.000 Punch Out 13
-1 2017-04-24 22:00:00.000 Punch Out 14 Store Close
结果:
Header | Header
-------------------- | ------
No. Of Emp At Open | 3
No. Of Emp At Close | 4
最佳答案
您可以使用以下查询来查找该员工是否仍在办公室。然后,您可以从此查询的输出中计算在办公室和不在办公室的员 worker 数。
SELECT in.EmployeeID ,
CASE WHEN out.EmployeeID IS NULL
THEN 1
ELSE 0
END AS Still_In_Office
FROM Employee in
LEFT OUTER JOIN Employee out ON in.EmployeeID = out.EmployeeID
AND out.Type = "Punch Out"
WHERE in.Type = "Punch In"
关于mysql - 选择并计算一天开始和结束时的条目数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44535728/