相互关注问题

from_user指关注行为的发起者,to_user指被关注的人,用两张原数据表互相关联,条件为t1.from_user=t2.to_user and t1.to_user=t2.from_user,这样就能表示互相关注。

总体sql:

select t1.from_user,t1.to_user,if(t2.from_user is not null,1,0)as is_friend ->is_friend为1则表示两用户已经相互关注了

from follow t1 left join follow t2

on t1.from_user=t2.to_user and t1.to_user=t2.from_user

全部评论

相关推荐

真的很糟糕:不一定是你的问题,当然你也可以做的更好一些,继续投相信自己一定会有的
点赞 评论 收藏
分享
牛客30771517...:SQL注入这一块
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务