思路分析:通过为每一队分配一个id,join条件要求t1.num < t2.num实现相同两队只比一次
代码实现:
with t as (
SELECT team_name,
case
team_name
WHEN '勇士' then 1
WHEN '湖人' then 2
WHEN '灰熊' then 3
else 4
end num
FROM team
)
SELECT
t1.team_name team_name_1,
t2.team_name team_name_2
FROM t t1
JOIN t t2
WHERE t1.num < t2.num