SQL Project Planning

  • + 0 comments

    MySQL query :

    with cte as ( Select start_date,end_date from projects order by start_date asc )

    ,cte2 as ( Select *, end_date - row_number() over (order by start_date) as id from cte )

    ,cte3 as ( Select min(start_date) as start_datemin,max(end_Date) as end_datemax, max(end_Date)-min(start_date) as delay from cte2 group by id )

    Select start_datemin,end_datemax from cte3 order by delay asc, start_datemin asc