Calculate total time excluding overlapped time & breaks in MySQL -
There is a list of start time and end time from a selected query, overlapping time and the total time address except for any break Will have to be installed.
Start time expiration date 2014-10-01 10: 30: 00.000 2014-10-01 12: 00: 00,000 - 90 minutes 2014-10-01 10: 40: 00.000 2014-10 -01 12: 00: 00.000 --0 because it overlaps with previous 2014-10-01 10: 42: 00.000 2014-10-01 12: 20: 00.000 - 20 minutes except overlap time 2014-10-01 10: 40: 00.000 2014-10-01 13: 00: 00.000 - 40 minutes 2014-10-01 10: 44: 00.000 2014-10-01 12:21: 00.000 - 0 Previous times this time frame 2014-10-13 15: 50: 00.000 2014-10-13 16: 00: 00.000 - 10 min
There are so many covers in this case it should be 160 minutes.
I have some ideas with lots of loops and if there is only one available in search of some simple solutions.
This problem is the interval and the type of islands is a way to deal with it here
< Preclass = "lang-sql prettyprint-override"> SELECT SUM (minutes) from the total (SELECT TIMESTAMPDIFF (MINUTE, MIN (start time), MAX (end time)) minutes (SELECT start, end time, @g : = If (Table 1 cross join (SELECT @g: = 0, @ E: =) (initial time and expiry time or end time & lt; @e, @ g, @ g + 1) NULL) I start time, end time) by G group G) q
Output:
| Total. ------- | | 160 |
Here is a demo
Comments
Post a Comment