如何显示结果,如印度与巴基斯坦,印度与斯里兰卡,印度与孟加拉国,孟加拉国与斯里兰卡,孟加拉国与巴基斯坦,巴基斯坦与斯里兰卡的结果如下表所示?
Teams
-------
India
Pakistan
Sri Lanka
Bangladesh
例如:
--Output:
Bangladesh vs. India
Bangladesh vs. Sri Lanka
Bangladesh vs. Pakistan
India vs. Sri Lanka
India vs. Pakistan
Pakistan vs. Sri Lanka
答案 0 :(得分:1)
我猜你正在寻找不重复的团队比赛组合。请尝试以下:
CREATE TABLE temp
(
Team VARCHAR(100)
)
INSERT INTO temp
VALUES ('India'),
('Bangladesh'),
('Sri Lanka'),
('Pakistan')
SELECT t1.team + ' vs. ' + t2.team
FROM temp t1
CROSS JOIN temp t2
where t1.Team < t2.Team
DROP TABLE temp
Result
-----------
India vs. Sri Lanka
India vs. Pakistan
Bangladesh vs. India
Bangladesh vs. Sri Lanka
Bangladesh vs. Pakistan
Pakistan vs. Sri Lanka