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