Study - Problems(IT)/LeetCode - SQL

1729.Find Followers Count

Dev.D 2024. 11. 24. 23:49

* Problem

Write a solution that will, for each user, return the number of followers. Return the result table ordered by user_id in ascending order.

 

* Explanation

The followers of 0 are {1}
The followers of 1 are {0}
The followers of 2 are {0,1}

 

* Solution (Success)

# Write your MySQL query statement below
select user_id, count(follower_id) followers_count 
    from Followers
   group by user_id
   order by user_id