gpt4 book ai didi

sql - 使用内连接两次

转载 作者:行者123 更新时间:2023-12-03 02:59:38 24 4
gpt4 key购买 nike

尝试选择匹配表并将 ID 转换为学校名称,但现在我一次只能处理一行。我的选择会是什么样子?

select Match.ID, School, GuestTeamID from Match
inner join Team on team.id = match.HomeTeamID

比赛表

+------------+------------+-------------+
| ID | HomeTeamID | GuestTeamID |
+------------+------------+-------------+
| 1 | 1 | 2 |
| 2 | 3 | 4 |
+------------+------------+-------------+

团队表:

+----+----------+
| ID | School |
+----+----------+
| 1 | School A |
| 2 | School B |
| 3 | School C |
| 4 | School D |
+----+----------+

最佳答案

将 Team 表与 Match 表加入两次以获取学校名称。

试试这个:

SELECT M.ID, t1.School AS HomeSchool, t2.School AS GuestSchool
FROM MATCH m
INNER JOIN Team t1 ON t1.id = m.HomeTeamID
INNER JOIN Team t2 ON t2.id = m.GuestTeamID;

关于sql - 使用内连接两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27858459/

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