The simple solution with self join


  • 0
    S

    To find the follower list when as a followee by using self join.

    Point 1. from follow f1, follow f2
    0_1503811735952_Screen Shot 2017-08-26 at 10.28.29 PM.png

    Point 2. where f1.follower = f2.followee

    0_1503811743951_Screen Shot 2017-08-26 at 10.28.39 PM.png

    Point 3. Use count distinct for unique f2.follower

    The simple Solution:
    select f1.follower, count(distinct f2.follower) as num
    from follow f1, follow f2
    where f1.follower = f2.followee
    group by f1.follower;


Log in to reply
 

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