![](/img/trans.png)
[英]Selecting a random row from a Postgres table using multiple AND statements
[英]Postgres selecting from table row
我有表團隊,其中包含這樣的列
team_id | name | competition_id
--------+---------+------
1 | name 1 | 10
2 | name 2 | 10
而且我也有這個桌子固定裝置
fixture_id | home_team_id | away_team_id | competition_id
--------+--------------+--------------+--------------
1 | 1 | 2 | 10
2 | 2 | 1 | 10
桌上固定裝置的主鍵是fixture_id,home_team_id,away_team_id和Competition_id。 home_team,away_team和比賽也是外鍵。
如何從固定裝置中選擇home_team_name,away_team_name。
您可以兩次加入“ teams
表中的“ fixtures
表-一次用於主隊,一次用於客隊:
SELECT fixture_id, home.name, away.name
FROM fixtures f
JOIN teams home on home.team_id = f.home_team_id
JOIN teams away on away.team_id = f.way_team_id
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.