Using two variables, <1000ms


  • 2
    L
    # Write your MySQL query statement below
    select Id 
    from(
            select 
                w.Id, 
                if(@prev<Temperature && DATEDIFF(@prevD,Date)=-1,1,0) as increased,
                @prev := w.Temperature, 
                @prevD :=w.Date
            from 
                (select * from Weather order by Date asc) w, # order the dates
                (select @prev := 10000) p, 
                (select @prevD := null) d
        ) a
    where 
    increased = 1;

  • 0
    H

    @LeetPine Awesome solution inspires me a lot!


Log in to reply
 

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