php - matching logs with schedule on flexi-time -
i'm working on module system able determine logs of flexi-time schedule belong...
here's i'm trying do. have table called office_schedule fields , values:
emp_id time_in time_out 1 8:00:00 9:00:00 1 9:30:00 12:00:00 1 13:30:00 17:00:00 the example table above 'office_schedule' contains values of schedule of single employee in single day. given have table called 'office_logs' value:
emp_id log_in log_out 1 8:40:00 11:30:00 i searching query take employee's logs , try determine value in 'office_schedule' table logs belong to, calculating value of time has covered.
for example, if query using logs in 'office logs' table, match second value of 'office_schedule' table, because logs cover more span of time in 'office_schedule' table's second value others.
i hope understandable enough. please help...
assuming time cells defined time , not varchar, try (but maybe there better way):
select * `office_logs` log left join `office_schedule` sched on log.`emp_id` = sched.`emp_id` log.`emp_id` = 1 order (abs(sched.`time_in` - log.`log_in`) + abs(sched.`time_out` - log.`log_out`)) asc limit 1; it calculates absolute difference between log in , log out times of employee each of scheduled time in , time out. return ordered smallest difference.
maybe helps.
Comments
Post a Comment