You are viewing a single comment's thread. Return to all comments →
WITH cte AS( SELECT COALESCE(LAG(start_date) OVER(ORDER BY start_date), '1900-01-01') AS prev_date, start_date, end_date, COALESCE(LEAD(end_date) OVER(ORDER BY end_date), '2100-01-01') AS next_date FROM projects), cte2 AS ( SELECT start_date, ROW_NUMBER() OVER(ORDER BY start_date) AS rn FROM cte WHERE ABS(DATEDIFF(DAY, start_date, prev_date)) <> 1), cte3 AS ( SELECT end_date , ROW_NUMBER() OVER(ORDER BY end_date) AS rn FROM cte WHERE ABS(DATEDIFF(DAY, next_date, end_date)) <> 1) SELECT cte2.start_date, cte3.end_date FROM cte2 JOIN cte3 ON cte2.rn = cte3.rn ORDER BY ABS(DATEDIFF(DAY, cte2.start_date, cte3.end_date)), cte2.start_date;
Seems like cookies are disabled on this browser, please enable them to open this website
SQL Project Planning
You are viewing a single comment's thread. Return to all comments →