各位,
最近我遇到了一个问题,我无法得到实际的答案。请给我一些建议,以达到预期的效果。
InputDataset
Table Name : Country_List
Country
Ind
Aus
China
Us
Eng
NL
Pak
SRL我需要得到上述数据集的可能组合,如country1 vs country2。
预期结果
Ind Vs Pak
Ind Vs Aus
China VS ind
China Vs US
SRL VS Ind同样,我需要得到所有可能的组合,没有重复。
注意: Ind VS Pak和Pak Vs Ind都是same.we,只需要一个就可以了。
发布于 2020-05-07 08:52:09
您可以尝试下面的逻辑
WITH CTE
AS(
SELECT *,
ROW_NUMBER() OVER(ORDER BY Country) RN
FROM Country_List
)
SELECT DISTINCT A.Country, B.Country
FROM CTE A
INNER JOIN CTE B ON A.RN < B.RN发布于 2020-05-07 11:52:05
我认为你只想要一个带有不等式的cross join或join:
select cl1.country, cl2.country
from Country_List cl1 cross join
Country_List cl2
where cl1.country < cl2.country;https://stackoverflow.com/questions/61653501
复制相似问题