Solution by using Join Only.


  • 0
    H
    # Write your MySQL query statement below
    SELECT DISTINCT a.Num As ConsecutiveNums
    FROM Logs a
    JOIN Logs b
    ON a.Num = b.Num
    JOIN Logs c
    ON b.Num = c.Num
    WHERE a.Id + 1 = b.Id
    ANd b.Id + 1 = c.Id

  • 0
    I

    You should use join on a.id+1=b.id

    not nums

    otherwise your runtime is very bad.


  • 0
    H

    I wonder which clause be executed first? On or Where?
    Run time Improves from 1595 ms beats 67.25% To 1671 ms beats 42.11%


Log in to reply
 

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