我有一个包含三行的列表,如下所示:
COL1
TEAM1
TEAM2
team3
team4
我想按照以下结果进行自笛式加入:
team1,team2
team1,team3
team1,team4
team2,team3
team2,team4
team3,team4
答案 0 :(得分:3)
cartesian product
为cross join
,您可以删除where
子句中团队相等的行:
select
t1.col1, t2.col1
from teams as t1
cross join teams as t2
where
t1.col1 <> t2.col1
答案 1 :(得分:1)
您可以将两个表连接在一起以获得预期的输出,如下所示:
select t1.col1, t2.col1
from table t1
join table t2
on t1.col1 <> t2.col1