编写解决方案,对于每一个用户,返回该用户的关注者数量。 #按 user_id 的顺序返回结果表
题目链接:
https://leetcode.cn/problems/find-followers-count/description/
建表插入语句:
Create table If Not Exists Followers(user_id int, follower_id int)
Truncate table Followers
insert into Followers (user_id, follower_id) values ('0', '1')
insert into Followers (user_id, follower_id) values ('1', '0')
insert into Followers (user_id, follower_id) values ('2', '0')
insert into Followers (user_id, follower_id) values ('2', '1')
画图分析:
代码实现:
select user_id,
count(follower_id) as followers_count
from Followers group by user_id order by user_id;