SQL problem - Find Followers Count
Problem
Query
Note:
- (user_id, follower_id) is unique
- user
COUNT
function to count the occurences of a singleuser_id
COUNT
aggregation function often requires the field to aggregate by => done by usingGROUP BY
clause
ORDER BY
TO order the result by ascending order
SELECT user_id, COUNT(follower_id) AS followers_count
FROM Followers
GROUP BY user_id
ORDER BY user_id ASC