This are the logs of employee # 16
And here is my expected output
I've tried this query :
SELECT a.`id` AS employ_id,
ADDTIME(MIN(a.adjustedDateTime), '12:00:00') AS check_in_time,
ADDTIME(MAX(a.adjustedDateTime), '12:00:00') AS check_out_time,
TIMEDIFF(
MAX(a.adjustedDateTime),
MIN(a.adjustedDateTime) ) AS working_time,
COUNT(0) AS report_times,
DATE_FORMAT(a.adjustedDateTime, '%Y-%m-%d') AS report_date
FROM (SELECT
`EnNo` AS id,
SUBTIME(
CONCAT(DATE(DateTime), ' ', TIME(DateTime)), '12:00:00') AS adjustedDateTime
FROM
bio) a
GROUP BY a.`id`,
DATE_FORMAT(a.adjustedDateTime, '%Y-%m-%d')
ORDER BY a.`id`, DATE('DateTime');
[And here is the output, not calculating the dayshift hours :
--- Empid - | ----------TimeIn---------- |----------TimeOut------- |----------Hours----- |
00000006 2017-05-15 18:14:13 2017-05-16 06:30:05 12:15:52.000000 00000006 2017-05-16 18:10:18 2017-05-17 05:30:50 11:20:32.000000 00000006 2017-05-18 08:30:05 2017-05-18 08:30:05 00:00:00.000000 00000006 2017-05-18 15:30:05 2017-05-18 15:30:05 00:00:00.000000
Can anyone help me with this? or any suggestion with it's algorithm or anything. Thanks. Sorry if I can't post the images, not enough reputation :(
Basically you have the following:
Now, what is night-shift?
So, instead of simply using "start of work" timestamp, you use the maximum between this start of work and 10pm and the minimum of end-of-work and 7am:
Note that I had to add some conditions to guess which is a probable end-of-work time (before noon) and which is a probable start-of-work-time (after noon) for this nightshift calculation:
For final solution you'd have to add in employee id and so on...