accountbase :用户信息表 accountattention:用户关注或粉丝的关联关系表 查询粉丝列表,同时显示当前用户与粉丝用户是否是相关关注状态,返回 1:代表互关,0:只是粉丝 100000009 :代表某个用户id
查询代码如下:
select accid, accountname,wxnickname,wxuserpic,accountpic,1 from accountbase bb where exists ( select a.accid from (select accid, attentaccid from accountattention where attentaccid = 100000009 and delflag = 0 ) a where (select count(*) from (select accid, attentaccid from accountattention where accid = 100000009 and delflag = 0 ) b where a.accid = b.attentaccid )=1 and a.accid = bb.accid ) union select accid, accountname,wxnickname,wxuserpic,accountpic,0 from accountbase bb where exists ( select a.accid from (select accid, attentaccid from accountattention where attentaccid = 100000009 and delflag = 0 ) a where (select count(*) from (select accid, attentaccid from accountattention where accid = 100000009 and delflag = 0 ) b where a.accid = b.attentaccid )=0 and a.accid = bb.accid )图:
解释语句: 获取 100000009 的粉丝用户id: select accid, attentaccid from accountattention where attentaccid = 100000009 and delflag = 0 获取100000009 的关注用户id: select accid, attentaccid from accountattention where accid = 100000009 and delflag = 0 获取是100000009的粉丝但不是100000009的关注用户id: select a.accid from (select accid, attentaccid from accountattention where attentaccid = 100000009 and delflag = 0 ) a where ( select count(*) from (select accid, attentaccid from accountattention where accid = 100000009 and delflag = 0 ) b where a.accid = b.attentaccid ) =0 例如: