[英]Schedule of cricket matches sql query
I have a table with list of countries as shown below. 我有一张带有国家/地区列表的表格,如下所示。 Every country will play against all countries in the list.
每个国家都将与列表中的所有国家对战。 I need a query to display the list of opponent countries in format (country1, country2) for all the possible matches without repetitions.
我需要查询以所有可能的匹配形式(国家/地区,国家/地区2)显示对手国家的列表,而无需重复。 eg c1 & c2 will play against each other.
例如c1和c2会互相对抗。 Display list should not have c2 & c1 (repetition)
显示列表不应包含c2和c1(重复)
CtryName
---
c1
c2
c3
c4
c5
It's an interview question. 这是一个面试问题。 I have no idea how to get expected results.
我不知道如何获得预期的结果。 Please help me by a simple query to display expected results.
请通过一个简单的查询来帮助我,以显示预期的结果。
Try like this: 尝试这样:
select t1.c teamA, t2.c teamB
from test t1,
test t2
where t1.c < t2.c
order by t1.c, t2.c
I named the table as test
and the country column as c
. 我将表命名为
test
,将country列命名为c
。
See it here on fiddle: http://sqlfiddle.com/#!6/9124f/2 在小提琴上看到它: http ://sqlfiddle.com/#!6/ 9124f/2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.