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 ProjectGroup AS(
SELECT Start_Date,
End_Date,
DATEDIFF(day, '1900-01-01', End_Date) - ROW_NUMBER() OVER(order by End_Date) AS Consecutive_Date_Group
FROM Projects
),
ProjectCompletion AS (
SELECT MIN(Start_Date) AS Date_Start,
MAX(End_Date) AS Date_End,
COUNT(Consecutive_Date_Group) AS Day_Complete
FROM ProjectGroup
GROUP BY Consecutive_Date_Group
)
SELECT Date_Start,
Date_End
FROM ProjectCompletion
ORDER BY Day_Complete, Date_Start
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 ProjectGroup AS( SELECT Start_Date, End_Date, DATEDIFF(day, '1900-01-01', End_Date) - ROW_NUMBER() OVER(order by End_Date) AS Consecutive_Date_Group FROM Projects ), ProjectCompletion AS ( SELECT MIN(Start_Date) AS Date_Start, MAX(End_Date) AS Date_End, COUNT(Consecutive_Date_Group) AS Day_Complete FROM ProjectGroup GROUP BY Consecutive_Date_Group )
SELECT Date_Start, Date_End FROM ProjectCompletion ORDER BY Day_Complete, Date_Start