less than 1 minute read

Problem

problem

Query

Note:

  • (user_id, follower_id) is unique
  • user COUNT function to count the occurences of a single user_id
    • COUNT aggregation function often requires the field to aggregate by => done by using GROUP 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

Tags:

Updated: