An answer using variable and case clause, and it seems running very slow


  • 0
    A
    set @i = 0;
    select distinct s.id, s.date, s.people
    from (
        select id
            , case when people >= 100 then @i := @i + 1 else @i := 0 end as flag
        from stadium s
        order by id
    ) tmp
    join stadium s on tmp.flag >= 3 and s.id >= tmp.id - 2 and s.id <= tmp.id
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.