Sql查询来安排每个团队之间的匹配 [英] Sql query to schedule a match between each teams

查看:87
本文介绍了Sql查询来安排每个团队之间的匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have a table with these columns like,
country
-------
India
Pak
Aus
I need to generate the output like,
Output:
-------
India vs Aus
India vs Pak
Pak vs Aus





我尝试过:



我尝试使用Sqlsever加入使用row_numbers(),但我无法解决。任何人都可以帮我解决这个问题。



What I have tried:

I have tried with Sqlsever joins with using row_numbers() but i unable to solve . Can anyone help me out this.

推荐答案

你使用JOIN走在正确的轨道上;棘手的部分是选择在其上使用哪个运算符。



You are on the right track with using a JOIN; the tricky part is choosing which operator(s) to use on it.

DECLARE @table TABLE (
   ndx INT IDENTITY(1,1) NOT NULL,
   Team VARCHAR(16)
)
INSERT @table
VALUES ('One')
,      ('Two')
,      ('Three')

SELECT  t1.Team, t2.Team
FROM       @table  t1
INNER JOIN @table  t2 ON t1.ndx < t2.ndx



这将给你回报


Will return you this

Home  Guest
----  -----
One   Two
One   Three
Two   Three


Google是你的朋友:一定要经常拜访他。



一个基本的谷歌给了我600多万次点击:组合sql - Google搜索 [ ^ ] - 按照任何链接(相当多),你会找到解决方案。
Google is your friend: be sure to visit him often.

A basic google gave me over 6 million hits: combinations sql - Google Search[^] - follow any link (pretty much) and you'll find the solution.


这篇关于Sql查询来安排每个团队之间的匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆