我这没问题啊。
还有个思路:
select * from tb t1 where t1.id<t1.otherID and exists(select 1 from tb t2 where t1.id=t2.otherID and t1.otherID=t2.id)
查出来的都是id<otherid的那一条,然后java代码中循环遍历的时候add两条就可以
add(id,otherid)
add(otherid,id)[/quote]
恩,好的,谢谢了哈
我这没问题啊。
还有个思路:
select * from tb t1 where t1.id<t1.otherID and exists(select 1 from tb t2 where t1.id=t2.otherID and t1.otherID=t2.id)
查出来的都是id<otherid的那一条,然后java代码中循环遍历的时候add两条就可以
add(id,otherid)
add(otherid,id)
那就再嵌套一层
select id,otherID from(select *,groups=(case when t1.id<t1.otherID then rtrim(t1.id)+','+rtrim(t1.otherID) else
rtrim(t1.otherID)+','+rtrim(t1.id) end) from tb t1 where exists(select 1 from tb t2 where t1.id=t2.otherID and t1.otherID=t2.id)
)t order by groups[/quote]
这个groups提示没这一行
那就再嵌套一层
select id,otherID from(select *,groups=(case when t1.id<t1.otherID then rtrim(t1.id)+','+rtrim(t1.otherID) else
rtrim(t1.otherID)+','+rtrim(t1.id) end) from tb t1 where exists(select 1 from tb t2 where t1.id=t2.otherID and t1.otherID=t2.id)
)t order by groups