I need to sum up the time which results from multiple time ranges. For example - we have enter / exit ranges of some office:
Query has to:
- Exclude overlapping ranges (8:00 - 10:00)
- Exclude "missing" part (12:00 - 14:00)
Expected result in this case is 8:00 (8:00 to 12:00 + 14:00 to 18:00)
Example table structure:
DAY | TIME_ENTER | TIME_EXIT
2016-01-01 | 08:00 | 10:00
2016-01-01 | 08:00 | 12:00
2016-01-01 | 14:00 | 18:00
Expected result:
DAY | TOTAL
2016-01-01 | 08:00
Table structure:
CREATE TABLE Registry
(`Date` DATE,
`Enter` TIME,
`Exit` TIME);
Example inserts
INSERT INTO Registry
VALUES
('2016-01-01', '08:00', '09:00'),
('2016-01-01', '08:00', '12:00'),
('2016-01-01', '14:00', '18:00')
