ard*_*var 7 sql database twitter-follow
我在mySQL中有一个基本的关注者/关注表,看起来像这样.
id user_id follower_id
1 userA userB
2 userC userA
3 userA userC
4 userB userC
5 userB userA
Run Code Online (Sandbox Code Playgroud)
我检查了这些主题,但无法找到我需要的东西
我需要的是拥有这样一个系统:
假设我们是userB(我们关注userA,接下来是userC和userA)
我想返回包含此关注者/关注状态的结果.例如对于userB:
id followedBy areWeFollowing
1 userA 1
2 userC 0
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
阿尔达
通过此查询来查找您是否关注了谁,也关注您。
SELECT ff1.follower_id as followedBy,
(
select count(follower_id)
from follower_following as ff2
where ff2.user_id = ff1.follower_id
and ff2.follower_id = ff1.user_id
) as areWeFollowing
FROM follower_following as ff1
where user_id = 'userB';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2696 次 |
| 最近记录: |