2014-01-08 19 views
0

我有三個表:玩家,統計和團隊。如何連接2個不返回單值的suqueries? MySQL

**Player Table** **Team Table** 
----------------- ---------------- 
id Name  Age id Team Ratio 
----------------- ---------------- 
1 Player1 15  1 Team1 10 
2 Player2 20  2 Team2 5 
3 Player3 40  3 Team3 40 


**Stats Table** 
----------------------------- 
TName Column Value A B 
----------------------------- 
Player Age  Young 10 30 
Player Age  Mature 30 50 
Player Age  Old 50 70 
Team Ratio Good 20 40 
Team Ratio Medium 8 20 
Team Ratio Bad  0 8 

我必須寫一些成員函數,它會告訴我結果誰該組是老模糊查詢:

select function(Player.age, Stats.A, Stats.B) from Player join Stats where TName = 'Player' 

另一項任務是編寫查詢,這將告訴我誰擁有不良率:

select function(Team.ratio, Stats.A, Stats.B) from Team join Stats where TName = 'Team' 

問題是我需要在一張桌子上顯示這個結果。我試圖子查詢select (first_query),(second_query),但我得到了錯誤Subquery returns more than 1 row

編輯

我沒有粘貼在這裏我的表,但我做的是簡單的版本。正因爲如此,結果可能是無效的:

我:

**function(Player.age, Stats.A, Stats.B)** 
------------------------------------------ 
0.22222 
0.44444 
1 

**function(Team.ratio, Stats.A, Stats.B)** 
------------------------------------------ 
0.52 
0.1 
0 

但我想有:

|**function(Player...) | function(Team...)**| 
| ----------------------------------------| 
| 0.22222   | 0.52   | 
| 0.44444   | 0.1    | 
| 1     | 1    | 
+0

請編輯您的問題以顯示您想要的結果集樣本。 –

+0

但0.22222和0.52之間的相關性是多少? – verhie

+0

你可以給這兩個子查詢一個自動遞增值嗎?然後你可以加入。 – verhie

回答

0

實際的答案是的vahidverhie意見相結合,這是它的樣子:

select pl,te from 
(select function(Player.age, Stats.A, Stats.B), id from Player join Stats where TName = 'Player') as pl 
join 
(select function(Team.ratio, Stats.A, Stats.B), id from Team join Stats where TName = 'Team') as te 
on pl.id = te.id 

感謝您的幫助。

0

也許這個工作!

select * from (first_query) , (second_query) 
+1

你能澄清「也許」嗎? –

+0

這個問題是不明確的,如果每個表中有一個結果,那麼答案是正確的。 – vahid