1729. Find Followers Count
SQL 50 · Sorting and Grouping (day 4). Decode it with the hints, solve it on LeetCode, then compare with the reference solution in MySQLPostgreSQL.
Your work
Hints
Open one at a time. Try to finish with as few as you can.
1. What does one output row represent?
One user.
2. Approach
GROUP BY user_id, COUNT(follower_id), ORDER BY user_id.
3. The trap
Straight GROUP BY; nothing hidden.
Reference solution
Tested on MySQL 8.0 and PostgreSQL 16. Switch dialect at the top of the page.
Show the MySQLPostgreSQL solution
SELECT user_id, COUNT(follower_id) AS followers_count
FROM Followers
GROUP BY user_id
ORDER BY user_id;