Hi,
I need help with query. I have access log table something like this:
session_id (int) | user (varchar) | login_time (datetime) | logout_time (datetime)
1 | JOHN | 2007-03-02 15:32:01 | 2007-03-02 18:01:55
2 | JOHN | 2007-03-09 11:43:33 | 2007-03-09 21:02:25
3 | JOHN | 2007-03-15 22:00:05 | 2007-03-16 06:37:21
4 | MIKE | 2007-04-02 12:32:01 | 2007-03-02 14:01:55
5 | MIKE | 2007-03-09 10:41:33 | 2007-03-09 20:44:15
For a result I need report of working hours (user is a employee). The first idea was:
Code:
SELECT `user`, `login_time`, `logout_time`,
TIMEDIFF(`logout_time`, `login_time`) FROM `access_log`
ORDER BY `user`, `login_time`;
But access_log table may contain rows with a same time period (per user). For a example when user enters to the system twice from different PC-s (I can not disallow this), then this query gives double working hours
So I need somehow to take into consideration user time intersection.
Thank you in advance.