日期:2014-05-17 浏览次数:20656 次
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