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 myprojectscte AS(
SELECT
task_id,
start_date,
end_date,
(start_date) - ROW_NUMBER() OVER (ORDER BY start_date) as grp_id
FROM Projects
)
SELECT
MIN(start_date) AS start_date,
MAX(end_date) AS end_date
FROM myprojectscte
GROUP BY grp_id
ORDER BY (MAX(end_date)- MIN(start_date)) ASC, start_date ASC;
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 myprojectscte AS( SELECT task_id, start_date, end_date, (start_date) - ROW_NUMBER() OVER (ORDER BY start_date) as grp_id FROM Projects ) SELECT MIN(start_date) AS start_date, MAX(end_date) AS end_date FROM myprojectscte GROUP BY grp_id ORDER BY (MAX(end_date)- MIN(start_date)) ASC, start_date ASC;