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

In SQL, come posso generare ogni possibile combinazione univoca di 5!56?

Se per "set unici" intendi quello che penso tu faccia (scusate, non conosco APL!), potete scrivere:

SELECT e1.number,   e2.number,   e3.number,   e4.number,   e.number
  FROM elements e1, elements e2, elements e3, elements e4, elements e5
 WHERE e1.number < e2.number
   AND e2.number < e3.number
   AND e3.number < e4.number
   AND e4.number < e5.number
;

Sì, esiste un trucco Oracle per generare dati al volo, utilizzando la query gerarchica e la sintassi CTE:

WITH elements AS
( select rownum as number
  from dual
  connect by level <= 56 )
SELECT e1.number,   e2.number,   e3.number,   e4.number,   e.number
  FROM elements e1, elements e2, elements e3, elements e4, elements e5
 WHERE e1.number < e2.number
   AND e2.number < e3.number
   AND e3.number < e4.number
   AND e4.number < e5.number
;