从团队中选择 *;
| team_name | team_id |
| India | 1 |
| England | 2 |
| Germany | 3 |
| Japan | 4 |
从匹配中选择 *;
| match_id | match_date | hometeam | awayteam | homescore | awayscore |
| 1 | 2014-06-24 | 1 | 2 | 3 | 0 |
| 2 | 2014-06-25 | 3 | 4 | 0 | 2 |
Matches-table hometeam
和 awayteam
是 Teams-table team_id
的外键
我想要一个显示 homescore
和 awayscore
以及 team_names
最佳答案
你必须像这样将 matches 表与 teams 表连接起来:
SELECT th.team_name as team_home, m.homescore, ta.team_name as team_away, m.awayscore
FROM matches m
INNER JOIN teams th ON m.hometeam = th.team_id
INNER JOIN teams ta ON m.awayteam = ta.team_id
这里是 SqlFiddle
关于php - 我想用不同的值显示同一列两次 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20967762/