SQL Project Planning

  • + 0 comments

    MySQL

    set @st_date = CURDATE();
    with 
    f as (
        SELECT Start_Date st,
                (LAG(end_date) over w) lend,
                End_Date
        FROM Projects
        Window w as (ORDER BY Start_Date)
    ),
    f2 as (
        select
            if (f.lend = f.St, @st_date, @st_date := f.St) st,
            f.end_date end_date
        from f
    )
    select distinct
        f2.st, 
        MAX(f2.end_date) over start_d
    from f2
    window start_d as (partition by f2.st)
    order by (count(*) over start_d), f2.st
    ;