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] [Us
Give this a try:
select [User_id], sum([Time_count])/3600
from (
select [User_id],
case when [in_out]=1 then UNIX_TIMESTAMP([Date_time])
when [in_out]=0 then - UNIX_TIMESTAMP([Date_time])
end as [Time_count]
from my_table
) as a
group by [User_id]
I don't know MySQL syntax so if someone finds errors, please correct them.
Maybe could not work. For example if you have a user logged in. In that case you can filter only the users that has the same number of 1's and 0's in the [in_out]
field.