2012-10-18 88 views
-1

我有兩列(初級)[PLAYER_ID] [LEAUGE_ID]如何在Oracle中編寫此查詢?

是這樣的:

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

我試圖找到誰只有在leages 8和10起到相同的球員,所以雖然2441爲16,我們需要省略。

根據上面的表格,我想只找:

Player_id  League_id_1  League_id_2 
2441   8    10 

提前感謝!

+0

你的意思是你需要發揮*至少* 8和10 playes,只是不顯示其他記錄(同一玩家) ? –

+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是小提琴

+0

更簡單。 :) –

+0

這個工程!謝謝! – user1683987

+0

@ a.b我最終想要的查詢是屁股疼痛!但這是一個很大的幫助!再次感謝! – user1683987