码迷,mamicode.com
首页 > 其他好文 > 详细

A/B/C/D/E五个人互相传球

时间:2018-03-06 13:43:53      阅读:999      评论:0      收藏:0      [点我收藏+]

标签:not   union   union all   gpo   from   blog   dual   with   and   

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‘)
;

A/B/C/D/E五个人互相传球

标签:not   union   union all   gpo   from   blog   dual   with   and   

原文地址:https://www.cnblogs.com/moqingtong/p/8513733.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!