I think there is no need for DISTINCT


  • 0
    C
    SELECT a.Num FROM Logs a JOIN Logs b ON a.Id=b.Id+1 JOIN Logs c ON a.Id=c.Id+2 
     WHERE a.Num=b.Num AND b.Num=c.Num
    

    This should give the exact same result since there is no duplicate values after join.


  • 0

    Why don't you just submit it? Then you'll see it fail.


  • 0
    C

    I already tried and failed. Any idea why?


  • 0

    Because you don't handle duplicates. No idea why you think there can't be any.


  • 0
    C

    I cannot think of any duplicates. After JOIN with those ON conditions, there should be only five row left (111/211/121/212/221). And the WHERE condition will give you the first row which is 111. And since I only SELECT a.Num, it should be just 1.

    And I also created the table and ran it some where else and my code works. So I'm confused.


  • 0

    Why are you talking about the example case? That's not the one you fail.


Log in to reply
 

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