We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
WITH ConsecutiveDates AS (
SELECT
Start_Date,
End_Date,
DATEADD(day, -ROW_NUMBER() OVER (ORDER BY Start_Date), End_Date) AS GroupStart
FROM
Projects
)
SELECT
MIN(Start_Date) AS Start_Date,
MAX(End_Date) AS End_Date
FROM
ConsecutiveDates
GROUP BY
GroupStart
ORDER BY DATEDIFF(day, MIN(Start_Date), MAX(End_Date)) + 1,Start_Date
Cookie support is required to access HackerRank
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 →
WITH ConsecutiveDates AS ( SELECT Start_Date, End_Date, DATEADD(day, -ROW_NUMBER() OVER (ORDER BY Start_Date), End_Date) AS GroupStart FROM Projects ) SELECT MIN(Start_Date) AS Start_Date, MAX(End_Date) AS End_Date FROM ConsecutiveDates GROUP BY GroupStart ORDER BY DATEDIFF(day, MIN(Start_Date), MAX(End_Date)) + 1,Start_Date