clear markdown feedback
clear markdown feedback
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 3799354 fiddles created (41678 in the last week).

CREATE TABLE test (t_from DATETIME, t_till DATETIME);
 hidden batch(es)


INSERT INTO test VALUES ('2001-01-01','2001-01-03'), ('2001-01-05','2001-01-07'), ('2001-01-07','2001-01-09'), ('2001-01-11','2001-01-15'), ('2001-01-12','2001-01-14'), ('2001-01-17','2001-01-19'), ('2001-01-18','2001-01-20'), ('2001-01-19','2001-01-21');
 hidden batch(es)


select t_from, t_till from ( select @start t_from, @start := t_from t_till, @weight needed, @weight := @weight + weight from ( select t_from, 1 weight from test union all select t_till, -1 from test ) x, (select @weight := 0, @start := 0) y order by CAST(t_from AS DATE) ) z where needed = 0 and t_from > 0 and t_from != t_till;
t_from t_till
2001-01-03 00:00:00 2001-01-05 00:00:00
2001-01-09 00:00:00 2001-01-11 00:00:00
2001-01-15 00:00:00 2001-01-17 00:00:00
 hidden batch(es)