# Write your MySQL query statement below
2339. 联赛的所有比赛
表: Teams
+-------------+---------+ | Column Name | Type | +-------------+---------+ | team_name | varchar | +-------------+---------+ team_name 是该表中具有唯一值的列。 此表的每一行都显示了团队的名称。
编写解决方案,获取联赛中所有比赛。每两支球队进行两场比赛,其中一支球队是主队 home_team
,另一支是客场队 away_team
。
按 任意顺序 返回结果表。
返回结果格式如下例所示。
示例 1:
输入: Teams 表: +-------------+ | team_name | +-------------+ | Leetcode FC | | Ahly SC | | Real Madrid | +-------------+ 输出: +-------------+-------------+ | home_team | away_team | +-------------+-------------+ | Real Madrid | Leetcode FC | | Real Madrid | Ahly SC | | Leetcode FC | Real Madrid | | Leetcode FC | Ahly SC | | Ahly SC | Real Madrid | | Ahly SC | Leetcode FC | +-------------+-------------+ 解释: 该联赛的所有比赛都列在表格中。
原站题解
mysql 解法, 执行用时: 685 ms, 内存消耗: 0 B, 提交时间: 2023-10-15 16:49:45
# Write your MySQL query statement below SELECT home_team, away_team FROM ( SELECT t1.team_name home_team,t2.team_name away_team FROM Teams t1 JOIN Teams t2 ON t1.team_name != t2.team_name ) temp