且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL从查询结果中替换另一个表中的多个变量

更新时间:2022-12-12 12:31:19

基本上只进行两个联接,一个联接为家名,另一个联接为走人名.

basically just do two joins one for the home name and one for the away name.

SELECT 
     s.Game1_Time, 
     t.Team_Name as 'Home Team', 
     t1.Team_Name as 'Away Team'
FROM `SCHEDULE` s
JOIN `TEAM` t on t.Team_Number = s.Game1_Home_Team
JOIN `TEAM` t1 on t1.Team_Number = s.Game1_Away_Team

我添加了反引号,因为schedule是一个关键字,所以为了不弄乱任何内容,您应该在表名上使用反引号

i added backticks because schedule is a keyword so just to not mess anything up you should use backtics on the tablename

演示