欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 产业 > 力扣高频SQL 50题(基础版)第二十四题

力扣高频SQL 50题(基础版)第二十四题

2024/10/24 22:30:51 来源:https://blog.csdn.net/m0_70882914/article/details/140780941  浏览:    关键词:力扣高频SQL 50题(基础版)第二十四题

文章目录

  • 力扣高频SQL 50题(基础版)第二十四题
    • 1729.求关注者的数量
      • 题目说明
      • 实现过程
        • 准备数据
        • 实现方式
        • 结果截图

力扣高频SQL 50题(基础版)第二十四题

1729.求关注者的数量

题目说明

表: Followers

±------------±-----+

| Column Name | Type |

±------------±-----+

| user_id | int |

| follower_id | int |

±------------±-----+

(user_id, follower_id) 是这个表的主键(具有唯一值的列的组合)。

该表包含一个关注关系中关注者和用户的编号,其中关注者关注用户。

编写解决方案,对于每一个用户,返回该用户的关注者数量。

user_id 的顺序返回结果表。

实现过程

准备数据
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) followers_count from Followers group by user_id order by user_id;
结果截图

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com