sql - 使用sql替换具有不同列名的2列之间的列
问题描述
如何将 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
解决方案
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
推荐阅读
- amazon-web-services - 如何在扫描或描述 aws ecr 存储库中的图像的扫描文件时将环境变量作为输入到 imageTag
- mysql - GRANT 命令在 MySQL 中无法正常工作
- firebase - 如何编写 Firestore 安全规则以在单个字段中也允许空值和未定义值?
- dart - Dart timeout() 似乎在指定的持续时间后没有触发
- c - 检查数组是否是另一个数组的子集
- css - 使图像和文本的网格系统具有移动响应性
- latex - 如何将表格向左移动或不超过右边距?
- php - 如何分别显示从 0 到 4 的所有数组
- spring-boot - 用于获取映射的 Spring Boot 自定义验证注释
- automated-tests - selenide如何找到文档和IFrame里面的元素