sql - mysql 5.5.50 Calculate one day multiple events to one -


i have problem thinking , must ask help. create working time tracking system , can manage other things code, cannot figure out how can calculate following data.

fist, have couple tables , 1 store 4 things.

index | | timestamp           | 1     | 1   | 2016-09-21 08:00:00 | work 2     | 2   | 2016-09-21 08:01:00 | work 3     | 1   | 2016-09-21 10:00:00 | bin 4     | 2   | 2016-09-21 10:00:00 | bin 5     | 1   | 2016-09-21 10:15:00 | bout 6     | 2   | 2016-09-21 10:17:00 | bout 7     | 2   | 2016-09-21 13:00:00 | bin 8     | 1   | 2016-09-21 13:00:00 | bin 9     | 1   | 2016-09-21 13:30:00 | bout 10    | 2   | 2016-09-21 13:30:00 | bout 11    | 2   | 2016-09-21 15:58:00 | home 12    | 1   | 2016-09-21 16:05:00 | home 

i can nicely calculate times between work , home , got right value right person.

but i'm stuck break times.

i need calculate possible breaks per person , way total time spend breaks per person.

so need following answer when ask person 1 info:

who | time     | breaktime | working time 1   | 08:05:00 | 00:45:00  | 07:20:00 

or maybe persons can came same page when ask specific day...

who | time     | breaktime | working time 1   | 08:05:00 | 00:45:00  | 07:20:00 2   | 07:57:00 | 00:47:00  | 07:10:00 

there pairs events. work -> home , bin -> bout. , yes, there more persons , more brake times per person.

that might bad presentation, sorry (noob). hope give information can help. ask if there ask.

that code use when solve 1 day total time @ working place.

select timediff(   (select timestamp `stamps` (who '1' ,  date (timestamp) '2016-09-21' , 'home')), (select timestamp `stamps` (who '1' ,  date (timestamp) '2016-09-21' , 'work')) ) 

but cannot use multiple events.

that found. maybe not nice, works =).

$break = mysqli_query($conn,"select what, timestamp stamps (who '$id' ,  date (timestamp) '$day' , 'b%') order timestamp");  while($row = mysqli_fetch_array($break))  {   if ( $row['what'] == "bin" )    $start = strtotime( $row['timestamp'] );   else { $stop = strtotime( $row['timestamp'] );    $hours += ( $stop - $start );    }  } $btime = gmdate('h:i:s', floor($hours)); 

$btime gives 00:00:00 style result.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -