当前位置: 代码迷 >> Sql Server >> 怎么高效查询SNS中与用户是互粉的用户id号和个数
  详细解决方案

怎么高效查询SNS中与用户是互粉的用户id号和个数

热度:115   发布时间:2016-04-25 00:36:16.0
如何高效查询SNS中与用户是互粉的用户id号和个数
希望大虾们帮帮我这个小菜鸟,谢谢


fromuserid 表示关注者用户id 
touserid 表示被关注用户id


------解决方案--------------------
请问你想要的结果是什么?举个例子.

------解决方案--------------------

with test as 
(

select 1 id , 1 fromid,2 toid union 
select 2 id , 1 fromid,3 toid union 
select 3 id , 1 fromid,4 toid union 
select 4 id , 1 fromid,5 toid union 
select 5 id , 2 fromid,1 toid union 
select 6 id , 2 fromid,3 toid union 
select 7 id , 2 fromid,4 toid union 
select 8 id , 3 fromid,2 toid union 
select 9 id , 3 fromid,6 toid 
)
select  a.*
from test as a join test as b on a.toid = b.fromid and a.fromid = b.toid

  相关解决方案