Skip to content

Commit ec0ac17

Browse files
authored
Added task 1729.
1 parent 2bdcdb0 commit ec0ac17

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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

0 commit comments

Comments
 (0)