
234 PUZZLE 59 MERGING TIME PERIODS
PUZZLE
59 MERGING TIME PERIODS
When you have a timesheet, you often need to merge contiguous or
overlapping time periods. This can be a problem to do in a simple query,
so be careful as this is not easy to follow or understand:
CREATE TABLE Timesheets
(task_id CHAR(10) NOT NULL PRIMARY KEY,
start_date DATE NOT NULL,
end_date DATE NOT NULL,
CHECK(start_date <= end_date));
INSERT INTO Timesheets
VALUES (1, '1997-01-01', '1997-01-03'),
(2, '1997-01-02', '1997-01-04'),
(3, '1997-01-04', '1997-01-05'),
(4, '1997-01-06', '1997-01-09'),
(5, '1997-01-09', '1997-01-09'),
(6, '1997-01-09', '1997-01-09'),
(7, '1997-01-12', ...