What's caused the first access and the second wrong answer?


  • 1
    H

    first:

    select distinct Num as ConsecutiveNums
    from (select Num, if( @pre <> (@pre := Num) , @rank := 1 ,  @rank := @rank + 1 ) as rank
    from Logs as t1, (select @pre := 0 ) as t2
    order by t1.Id) as tt
    where tt.rank >= 3
    

    second:

    select distinct Num as ConsecutiveNums
    from (select Num, if( @pre <> (@pre := Num) , @rank := 1 ,  @rank := @rank + 1 ) as rank
    from Logs as t1, (select @pre := 1 ) as t2
    order by t1.Id) as tt
    where tt.rank >= 3
    

    The only difference is that the first one init the @pre := 0 and the second one init the @pre := 1


Log in to reply
 

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