Why this solution can't pass the 11/12 case?


  • 0
    M

    The expected answer and my output of the case is shown as follows, it seems that the different is the upper and lower case difference. Why that difference happened? And I think this should be the correct answer btw.
    0_1498884035282_无标题.png
    Below is my code:

    select f1.followee as follower, count(*) as num from 
    (select distinct followee, follower from follow f where f.followee in 
    (select distinct f2.follower from follow f2)) 
    f1 group by f1.followee
    

  • 1
    M

    By trying the AC answer, I found that the right answer is to use follower first to join the followee, while mine is to use followee to which exist in follower. So that's why mine get lowercase while correct one get uppercase. But I think these two solutions should be the same. Judging my lower case and upper case is not correct.


  • 0

    I've got the same issue here. Here is my code for the reference.

    select followee as follower, count(distinct followee, follower) as num
    from follow
    where followee IN ( select follower from follow )
    group by followee
    order by followee;
    

  • 0
    D

    I had the same issue too. Using follower first to join the followee now works for me. But, why do these two joins give different results?


  • 0
    M

    @drkarthi
    I think the difference is the first appearance of the same letter with lower or upper, when lower letter appear on the left table first, then it is lower, if upper appear on the left table first, then it is upper.


  • 0
    K

    Please refer to this code

    select a.follower, count(distinct b.follower) as num
    from follow a, follow b
    where a.follower = b.followee
    group by b.followee
    

  • 0
    C

    @Mr.Bin said in Why this solution can't pass the 11/12 case?:

    select followee as follower, count(distinct followee, follower) as num
    from follow
    where followee IN ( select follower from follow )
    group by followee
    order by followee;

    Got the same issue and my codes are essentially the same as Mr.Bin.

    Select f.followee as follower, count(distinct follower) as num from follow f
    Where f.followee in (select follower from follow)
    Group by f.followee
    Order by  f.followee
    

  • 0
    G

    @moveingsun
    "SELECT f2.follower as follower, count(distinct f1.follower) as num
    FROM
    follow f1
    INNER JOIN
    follow f2
    ON f1.followee=f2.follower
    GROUP BY f2.follower
    ORDER BY f2.follower;"

    gets accepted while

    "SELECT f1.followee as follower, count(distinct f1.follower) as num
    FROM
    follow f1
    INNER JOIN
    follow f2
    ON f1.followee=f2.follower
    GROUP BY f1.followee
    ORDER BY f1.followee;"

    which is a little baffling since the join condition is "f1.followee=f2.follower" !!
    The reason this happens is coz mysql string comparison is case insensitive so 'E'='e' return TRUE. Hence, it matters if you select f1.followee or f2.follower. Just pointing out in case it helps anyone.


Log in to reply
 

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