A/B/C/D/E五个人互相传球
WITH a AS(
SELECT ‘a‘ a FROM dual UNION ALL SELECT ‘b‘ a FROM dual UNION ALL
SELECT ‘c‘ a FROM dual UNION ALL SELECT ‘d‘ a FROM dual UNION ALL
SELECT ‘e‘ a FROM dual)
,a1 AS(
SELECT a.a a ,a1.a a1
FROM a a ,a a1
WHERE a.a=‘a‘ AND NOT (a.a=a1.a) AND NOT (a.a=‘a‘ AND a1.a=‘b‘)
AND NOT (a.a=‘b‘ AND a1.a=‘a‘))
,a2 AS(
SELECT a1.* ,a.a a2
FROM a1 ,a
WHERE NOT (a.a=a1.a1) AND NOT (a.a=‘a‘ AND a1.a1=‘b‘) AND NOT (a.a=‘b‘ AND a1.a1=‘a‘)
AND NOT (a.a<>‘d‘ AND a1.a1=‘c‘) AND NOT (a.a=‘c‘ AND a1.a1=‘e‘))
,a3 AS(
SELECT a2.* ,a.a a3
FROM a2 FULL JOIN a ON 1 = 1
WHERE NOT (a.a=a2.a2) AND NOT (a.a=‘a‘ AND a2.a2=‘b‘) AND NOT (a.a=‘b‘ AND a2.a2=‘a‘)
AND NOT (a.a<>‘d‘ AND a2.a2=‘c‘) AND NOT (a.a=‘c‘ AND a2.a2=‘e‘))
,a4 AS(
SELECT a3.* ,a.a a4
FROM a3 ,a
WHERE NOT (a.a=a3.a3) AND NOT (a.a=‘a‘ AND a3.a3=‘b‘) AND NOT (a.a=‘b‘ AND a3.a3=‘a‘)
AND NOT (a.a<>‘d‘ AND a3.a3=‘c‘) AND NOT (a.a=‘c‘ AND a3.a3=‘e‘))
SELECT *
FROM a4
WHERE a4.a4 NOT IN (‘b‘,‘a‘,‘c‘)
;