File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed
src/main/java/g1701_1800/s1729_find_followers_count Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ 1729\. Find Followers Count
2
+
3
+ Easy
4
+
5
+ SQL Schema
6
+
7
+ Table: ` Followers `
8
+
9
+ +-------------+------+
10
+ | Column Name | Type |
11
+ +-------------+------+
12
+ | user_id | int |
13
+ | follower_id | int |
14
+ +-------------+------+
15
+ (user_id, follower_id) is the primary key for this table.
16
+ This table contains the IDs of a user and a follower in a social media app where the follower follows the user.
17
+
18
+ Write an SQL query that will, for each user, return the number of followers.
19
+
20
+ Return the result table ordered by ` user_id ` .
21
+
22
+ The query result format is in the following example.
23
+
24
+ ** Example 1:**
25
+
26
+ ** Input:**
27
+
28
+ Followers table:
29
+ +---------+-------------+
30
+ | user_id | follower_id |
31
+ +---------+-------------+
32
+ | 0 | 1 |
33
+ | 1 | 0 |
34
+ | 2 | 0 |
35
+ | 2 | 1 |
36
+ +---------+-------------+
37
+
38
+ ** Output:**
39
+
40
+ +---------+----------------+
41
+ | user_id | followers_count|
42
+ +---------+----------------+
43
+ | 0 | 1 |
44
+ | 1 | 1 |
45
+ | 2 | 2 |
46
+ +---------+----------------+
47
+
48
+ ** Explanation:**
49
+
50
+ The followers of 0 are {1}
51
+
52
+ The followers of 1 are {0}
53
+
54
+ The followers of 2 are {0,1}
Original file line number Diff line number Diff line change
1
+ # Write your MySQL query statement below
2
+ # #Easy #Database #SQL_I_Day_7_Function #2022_04_30_Time_456_ms_(88.39%)_Space_0B_(100.00%)
3
+ select user_id, count (follower_id) as followers_count
4
+ from followers
5
+ group by user_id
6
+ order by user_id
You can’t perform that action at this time.
0 commit comments