I have a MySQL table where employee login and logout timings are recorded. Here in the in-out column 1-represents login and 0-represents logout.
[id] [User_id] [Date_time] [in_out]
1 1 2011-01-20 18:01:03 1
2 1 2011-01-20 19:30:43 0
3 1 2011-01-20 20:46:23 1
4 1 2011-01-21 00:42:45 0
Is it possible to retrieve total hours worked in a day (between 2 days) by a user using single query?
The same Question it's a copy of Get total hours worked in a day mysql and solution:
SELECT `User_id`, time(sum(`Date_time`*(1-2*`in_out`)))
FROM `whatever_table` GROUP BY `User_id`;
But the solution needs to be different when the employee start working in a day and go out on the next day.