2

我有一张朋友桌

PLAYER_ID    FRIEND_ID
----------------------
1            2
1            3         // 1 knows 3
3            1         // 3 knows 1
2            4

如何为给定的玩家创建一个包含那些熟人(彼此认识)的视图?

PLAYER_ID    FRIEND_ID
----------------------
1            3
3            1

谢谢你。

4

2 回答 2

2

这是所需的选择:

select t1.PLAYER_id, t1.FRIEND_ID from tablename t1
inner join tablename t2 on t1.PLAYER_id = t2.FRIEND_ID and t2.PLAYER_id = t1.FRIEND_ID
于 2012-06-11T08:22:08.763 回答
2
select p1.player_id, p1.friend_Id
from player p1 
inner join player p2 on p1.player_id = p2.friend_id and p2.player_id = p1.friend_id
于 2012-06-11T08:22:26.367 回答