1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/算法题/find-followers-count.html

48 lines
1.2 KiB
HTML
Raw Normal View History

2022-03-27 18:27:43 +08:00
<p>Table: <code>Followers</code></p>
<pre>
+-------------+------+
| Column Name | Type |
+-------------+------+
| user_id | int |
| follower_id | int |
+-------------+------+
(user_id, follower_id) is the primary key for this table.
This table contains the IDs of a user and a follower in a social media app where the follower follows the user.</pre>
<p>&nbsp;</p>
<p>Write an SQL query that will, for each user, return the number of followers.</p>
<p>Return the result table ordered by <code>user_id</code>.</p>
<p>The query result format is in the following example.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong>
Followers table:
+---------+-------------+
| user_id | follower_id |
+---------+-------------+
| 0 | 1 |
| 1 | 0 |
| 2 | 0 |
| 2 | 1 |
+---------+-------------+
<strong>Output:</strong>
+---------+----------------+
| user_id | followers_count|
+---------+----------------+
| 0 | 1 |
| 1 | 1 |
| 2 | 2 |
+---------+----------------+
<strong>Explanation:</strong>
The followers of 0 are {1}
The followers of 1 are {0}
The followers of 2 are {0,1}
</pre>