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 cte_start as
(
select
start_date,
row_number() over (order by start_date) as start_asc
from projects
where start_date not in (select end_date from projects)
), cte_end as
(
select
end_date,
row_number() over (order by end_date) as end_asc
from projects
where end_date not in (select start_date from projects)
)
select
start_date,
end_date
from cte_start, cte_end
where start_asc = end_asc
order by datediff(day,start_date, end_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
Cut the Tree
You are viewing a single comment's thread. Return to all comments →
easy solution. SQL server
with cte_start as ( select start_date, row_number() over (order by start_date) as start_asc from projects where start_date not in (select end_date from projects) ), cte_end as ( select end_date, row_number() over (order by end_date) as end_asc from projects where end_date not in (select start_date from projects) ) select start_date, end_date from cte_start, cte_end where start_asc = end_asc order by datediff(day,start_date, end_date) asc, start_date asc