gpt4 book ai didi

MySQL 双连接

转载 作者:可可西里 更新时间:2023-11-01 07:47:14 27 4
gpt4 key购买 nike

我有两个表:

teams
----------------
|uid|name |rank|
----------------
| 1 |Team1| 1 |
| 2 |Team2| 2 |
----------------

games
-----------------------------------------------------------------------
|uid|team_one_uid|team_one_score|team_two_uid|team_two_score|game_date|
-----------------------------------------------------------------------
|1|1|70|2|50|2012-12-12|

teams 表有一个团队列表和其他数据,例如排名。游戏表有一个游戏列表,并通过它的唯一 ID (uid) 引用每个团队。我可以运行什么查询来查看包含以下列的行的结果:

game_uid, team_one_name, team_one_rank, team_one_score, team_two_name, team_two_rank, team_two_score, game_date

最佳答案

select g.uid as game_uid, 
t1.name as team_one_name,
t1.rank as team_one_rank,
team_one_score,
t2.name as team_two_name,
t2.rank as team_two_rank,
team_two_score,
game_date
from games g
inner join teams t1 on t1.uid = team_one_uid
inner join teams t2 on t2.uid = team_two_uid

关于MySQL 双连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11853413/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com