Skip to content

Commit c405f85

Browse files
Create 1729. Find Followers Count.sql
Co-Authored-By: Antim-IWP <[email protected]>
1 parent 6527da5 commit c405f85

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

1729. Find Followers Count.sql

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
1729. Find Followers Count
2+
3+
+-------------+------+
4+
| Column Name | Type |
5+
+-------------+------+
6+
| user_id | int |
7+
| follower_id | int |
8+
+-------------+------+
9+
(user_id, follower_id) is the primary key (combination of columns with unique values) for this table.
10+
This table contains the IDs of a user and a follower in a social media app where the follower follows the user.
11+
12+
13+
Write a solution that will, for each user, return the number of followers.
14+
15+
Return the result table ordered by user_id in ascending order.
16+
17+
The result format is in the following example.
18+
19+
20+
21+
Example 1:
22+
23+
Input:
24+
Followers table:
25+
+---------+-------------+
26+
| user_id | follower_id |
27+
+---------+-------------+
28+
| 0 | 1 |
29+
| 1 | 0 |
30+
| 2 | 0 |
31+
| 2 | 1 |
32+
+---------+-------------+
33+
Output:
34+
+---------+----------------+
35+
| user_id | followers_count|
36+
+---------+----------------+
37+
| 0 | 1 |
38+
| 1 | 1 |
39+
| 2 | 2 |
40+
+---------+----------------+
41+
Explanation:
42+
The followers of 0 are {1}
43+
The followers of 1 are {0}
44+
The followers of 2 are {0,1}
45+
46+
47+
# Write your MySQL query statement below
48+
SELECT user_id, COUNT(follower_id) AS followers_count
49+
FROM Followers
50+
GROUP BY user_id
51+
ORDER BY user_id;

0 commit comments

Comments
 (0)