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 t1 as(
select start_date, end_date, row_number() over (order by end_date) as rn
from projects)
select sd, ed from (
select min(start_date) as sd, max(end_date) as ed, count(*) as cnt from (
select start_date, end_date, date_sub(end_date, interval rn day) as flag_date
from t1) a
group by flag_date
) b
order by cnt, sd
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 t1 as( select start_date, end_date, row_number() over (order by end_date) as rn from projects)
select sd, ed from ( select min(start_date) as sd, max(end_date) as ed, count(*) as cnt from ( select start_date, end_date, date_sub(end_date, interval rn day) as flag_date from t1) a group by flag_date ) b order by cnt, sd