given table:
create table Person( Name varchar(100) )
where Name is unique for all Persons
What SQL query can generate all possible n!/((n-2)!2!) round robin combinations?
It is assumed that the cardinality of Person is ALWAYS equal to 4
Example Person = {'Anna','Jerome','Patrick','Michael')
Output:
Anna, Jerome
Anna, Patrick
Anna, Michael
Jerome, Patrick
Jerome, Michael
Patrick, Michael
Any help would be appreciated. Thanks!
Here's my answer (I used oracle SQL):
select P1.NAME PERSON1, P2.NAME PERSON2
from (select rownum RNUM, NAME
from PERSON) P1,
(select rownum RNUM, NAME
from PERSON) P2
where P1.RNUM < P2.RNUM
Note that this is TSQL (Sql Server) syntax. I know that Oracle supports windowing functions, particularly row_number(), which is necessary for this solution.
It shouldn't be too hard to get this to work in Oracle with some trial and error
row_number assigns a row number to each row. You then need to join, as suggested before, with the additional join clause of p1.rownumber > p2.rownumber
Here are two solutions for the problem
OR (Oracle 11i R2+)