2016-04-03 122 views

回答

0

您需要兩次檢索「團隊」表,並在它們之間進行連接。

SELECT Game_Date, 
    Player.First_Name || ' ' || Player.Last_Name AS "PLAYER NAME", 
    UPPER(Team1.Team_Name) AS "HOME TEAM", 
    UPPER(Team2.Team_Name) AS "VISITING TEAM", 
    Team1.Team_City ||' '|| Team1.Team_Name as "TEAM", 
    Birth_Place1.Country 
FROM Game 
    JOIN Team Team1 ON Game.Team_Home_ID = Team1.Team_ID 
    JOIN Team Team2 ON Game.Team_Visitor_ID = Team2.Team_ID 
    JOIN Player Player1 ON Player1.Team_ID = Team1.Team_ID 
    JOIN Player Player2 ON Player2.Team_ID = Team2.Team_ID 
    JOIN Birth_Place Birth_Place1 ON Birth_Place1.Birth_Place_ID = Player1.Birth_Place_ID 
    JOIN Birth_Place Birth_Place2 ON Birth_Place2.Birth_Place_ID = Player2.Birth_Place_ID 
WHERE Birth_Place1.Country = Birth_Place2.Country 
    AND Season = '2015-2016' 
    AND Game_Date = '10-10-2015' 
    AND Birth_Place1.Country NOT IN ('CAN', 'USA') 
ORDER BY Birth_Place1.Country; 

不知道這是確切的正確的請求,但你的想法:訣竅是「Birth_Place1.Country = Birth_Place2.Country」 WHERE子句。

還重寫了國家/地區的WHERE子句,因爲它看起來像只過濾了兩個國家。

您可能會考慮複習一下您的體系結構,特別是Birth_Place表格:我猜如果您打算將其作爲過濾器使用,那麼在玩家表格中瞭解該玩家的國家是否合適。

+0

非常感謝,除了顯示正確的球員,但每個球員出現2次 – Carlos

+0

您的意思是一旦離開和一次回家,或?無論如何,您可以在SELECT之後添加DISTINCT關鍵字並查看它是否足夠? –

+0

沒有,甚至沒有,第一名球員出現4次,但來自瑞典的球員都不錯 – Carlos