如何将home_team_api_id和away_team_id的内容替换为真实姓名 我有2个表使用sql。第一个是离家出走ID,第二个是表1中对离家出走ID的描述
表1
home_team_api_id away_team_api_id
================ ================
8600 8540
9882 8636
8524 8551
8529 8543
8530 10233
表2
team_api_id team_long_name team_short_name
=========== ============== ===============
8600 Udinese UDI
9882 Sampdoria SAM
8524 Atalanta ATA
8529 Cagliari CAG
8530 Catania CAT
8540 Palermo PAL
8636 Inter INT
8551 Siena SIE
8543 Lazio LAZ
10233 Genoa GEN
所需结果
home_team_api_id away_team_api_id
================ ================
Udinese Palermo
Sampdoria Inter
Atalanta Siena
Cagliari Lazio
Catania Genoa
答案 0 :(得分:1)
以不同的别名两次加入table2
select home.team_long_name as home_team_api_id,
away.team_long_name as away_team_api_id
from table1
join table2 as home on home.team_api_id = table1.home_team_api_id
join table2 as away on away.team_api_id = table1.away_team_api_id