sql >> Database teknologi >  >> RDS >> Oracle

SQL Alle mulige Round Robin-kombinationer mellem to tabeller

Her er to løsninger på problemet

SELECT  t1.Name + ',' +  t2.Name AS NamesCombination
FROM Person t1
INNER JOIN Person t2
ON t1.Name < t2.Name
 

ELLER (Oracle 11i R2+)

WITH NamesCombination AS ( SELECT 1 AS Cntr ,Name , CAST(Name AS VARCHAR(MAX))AS NamesCombinations FROM Person UNION ALL SELECT nc.Cntr+1 ,p.Name ,nc.NamesCombinations + ',' + CAST(p.Name AS VARCHAR(MAX)) FROM Person AS p JOIN NamesCombination nc ON p.Name < nc.Name WHERE nc.Cntr < 2 ) SELECT NamesCombinations FROM NamesCombination WHERE Cntr = 2



  1. Mysql DISTINCT virker ikke, hvis jeg tilføjer en anden kolonne

  2. Sådan tilføjes Active Directory-brugergruppe som login i SQL Server

  3. MySQL INSERT INTO med PHP $variable

  4. vælg distinct count(id) vs select count(distinct id)