如何在Oracle中编写此查询?

时间:2012-10-18 14:58:38

标签: sql oracle join

我有两列(都是主要的)[PLAYER_ID] [LEAUGE_ID]

类似的东西:

Player_id      League_id
2139            8
2153            8
2302            10
2441            8
2441            10  
2441            16   

我正在尝试找到只在8和10中玩过的同一个玩家,所以尽管2441玩了16,我们需要省略它。

根据上表,我试图找到:

Player_id     League_id_1     League_id_2
2441          8               10

提前致谢!

1 个答案:

答案 0 :(得分:1)

尝试

select t1.player_id, t1.league_id league_id_1, t2.league_id league_id_2
  from table1 t1
  join table1 t2 on t1.player_id = t2.player_id
 where t1.league_id = 8
   and t2.league_id = 10

Here是一个小提琴