|
帖一下今天自己重做的:
SQL> with people(cno,country) as (select 1,'English' from dual
2 union all
3 select 2,'Swedish' from dual
4 union all
5 select 3,'Denish' from dual
6 union all
7 select 4,'Norwegian' from dual
8 union all
9 select 5,'German' from dual),
10 house(hno,color) as (select 1, 'Red' from dual
11 union all
12 select 2,'White' from dual
13 union all
14 select 3,'Yellow' from dual
15 union all
16 select 4,'Green' from dual
17 union all
18 select 5,'Blue' from dual),
19 drink(dno,name) as (select 1, 'Tea' from dual
20 union all
21 select 2,'Coffee' from dual
22 union all
23 select 3, 'Beer' from dual
24 union all
25 select 4, 'Milk' from dual
26 union all
27 select 5,'Water' from dual),
28 smoke(sno,brand) as (select 1, 'Pall Mall' from dual
29 union all
30 select 2,'Dunhill' from dual
31 union all
32 select 3,'Blends' from dual
33 union all
34 select 4,'Blue Master' from dual
35 union all
36 select 5,'Prince' from dual),
37 pet(pno,animal) as (select 1,'Dog' from dual
38 union all
39 select 2,'Bird' from dual
40 union all
41 select 3,'Cat' from dual
42 union all
43 select 4,'Horse' from dual
44 union all
45 select 5,'Fish' from dual),
46 people_rank(cno_rank) as (select replace(sys_connect_by_path(cno,','),',')
47 from people
48 where level=5
49 connect by nocycle prior cno <> cno),
50 house_rank(hno_rank) as (select replace(sys_connect_by_path(hno,','),',')
51 from house
52 where level=5
53 connect by nocycle prior hno <> hno),
54 drink_rank(dno_rank) as (select replace(sys_connect_by_path(dno,','),',')
55 from drink
56 where level=5
57 connect by nocycle prior dno <> dno),
58 smoke_rank(sno_rank) as (select replace(sys_connect_by_path(sno,','),',')
59 from smoke
60 where level=5
61 connect by nocycle prior sno <> sno),
62 pet_rank(pno_rank) as (select replace(sys_connect_by_path(pno,','),',')
63 from pet
64 where level=5
65 connect by nocycle prior pno <> pno)
66 select (select country
67 from people
68 where cno=substr(cno_rank,instr(pno_rank,5),1)
69 ) as country
70 from people_rank,
71 house_rank,
72 pet_rank,
73 drink_rank,
74 smoke_rank
75 where ( substr(cno_rank,1,1)=1 and substr(hno_rank,1,1)=1
76 or substr(cno_rank,2,1)=1 and substr(hno_rank,2,1)=1
77 or substr(cno_rank,3,1)=1 and substr(hno_rank,3,1)=1
78 or substr(cno_rank,4,1)=1 and substr(hno_rank,4,1)=1
79 or substr(cno_rank,5,1)=1 and substr(hno_rank,5,1)=1) --1
80 and ( substr(cno_rank,1,1)=2 and substr(pno_rank,1,1)=1
81 or substr(cno_rank,2,1)=2 and substr(pno_rank,2,1)=1
82 or substr(cno_rank,3,1)=2 and substr(pno_rank,3,1)=1
83 or substr(cno_rank,4,1)=2 and substr(pno_rank,4,1)=1
84 or substr(cno_rank,5,1)=2 and substr(pno_rank,5,1)=1) --2
85 and ( substr(cno_rank,1,1)=3 and substr(dno_rank,1,1)=1
86 or substr(cno_rank,2,1)=3 and substr(dno_rank,2,1)=1
87 or substr(cno_rank,3,1)=3 and substr(dno_rank,3,1)=1
88 or substr(cno_rank,4,1)=3 and substr(dno_rank,4,1)=1
89 or substr(cno_rank,5,1)=3 and substr(dno_rank,5,1)=1) --3
90 --and ( translate(hno_rank,'x135','x')= 42 )
91 and ( substr(hno_rank,1,1)=4 and substr(hno_rank,2,1)=2
92 or substr(hno_rank,2,1)=4 and substr(hno_rank,3,1)=2
93 or substr(hno_rank,3,1)=4 and substr(hno_rank,4,1)=2
94 or substr(hno_rank,4,1)=4 and substr(hno_rank,5,1)=2) --4
95 and ( substr(hno_rank,1,1)=4 and substr(dno_rank,1,1)=2
96 or substr(hno_rank,2,1)=4 and substr(dno_rank,2,1)=2
97 or substr(hno_rank,3,1)=4 and substr(dno_rank,3,1)=2
98 or substr(hno_rank,4,1)=4 and substr(dno_rank,4,1)=2
99 or substr(hno_rank,5,1)=4 and substr(dno_rank,5,1)=2) --5
100 and ( substr(sno_rank,1,1)=1 and substr(pno_rank,1,1)=2
101 or substr(sno_rank,2,1)=1 and substr(pno_rank,2,1)=2
102 or substr(sno_rank,3,1)=1 and substr(pno_rank,3,1)=2
103 or substr(sno_rank,4,1)=1 and substr(pno_rank,4,1)=2
104 or substr(sno_rank,5,1)=1 and substr(pno_rank,5,1)=2) --6
105 and ( substr(hno_rank,1,1)=3 and substr(sno_rank,1,1)=2
106 or substr(hno_rank,2,1)=3 and substr(sno_rank,2,1)=2
107 or substr(hno_rank,3,1)=3 and substr(sno_rank,3,1)=2
108 or substr(hno_rank,4,1)=3 and substr(sno_rank,4,1)=2
109 or substr(hno_rank,5,1)=3 and substr(sno_rank,5,1)=2) --7
110 and ( substr(dno_rank,3,1)=4 ) --8
111 and ( substr(cno_rank,1,1)=4 ) --9
112 and ( substr(sno_rank,1,1)=3 and substr(pno_rank,2,1)=3
113 or substr(sno_rank,2,1)=3 and (substr(pno_rank,1,1)=3 or substr(pno_rank,3,1)=3)
114 or substr(sno_rank,3,1)=3 and (substr(pno_rank,2,1)=3 or substr(pno_rank,4,1)=3)
115 or substr(sno_rank,4,1)=3 and (substr(pno_rank,3,1)=3 or substr(pno_rank,5,1)=3)
116 or substr(sno_rank,5,1)=3 and substr(pno_rank,4,1)=3) --10
117 and ( substr(pno_rank,1,1)=4 and substr(sno_rank,2,1)=2
118 or substr(pno_rank,2,1)=4 and (substr(sno_rank,1,1)=2 or substr(sno_rank,3,1)=2)
119 or substr(pno_rank,3,1)=4 and (substr(sno_rank,2,1)=2 or substr(sno_rank,4,1)=2)
120 or substr(pno_rank,4,1)=4 and (substr(sno_rank,3,1)=2 or substr(sno_rank,5,1)=2)
121 or substr(pno_rank,5,1)=4 and substr(sno_rank,4,1)=2) --11
122 and ( substr(sno_rank,1,1)=4 and substr(dno_rank,1,1)=3
123 or substr(sno_rank,2,1)=4 and substr(dno_rank,2,1)=3
124 or substr(sno_rank,3,1)=4 and substr(dno_rank,3,1)=3
125 or substr(sno_rank,4,1)=4 and substr(dno_rank,4,1)=3
126 or substr(sno_rank,5,1)=4 and substr(dno_rank,5,1)=3) --12
127 and ( substr(cno_rank,1,1)=5 and substr(sno_rank,1,1)=5
128 or substr(cno_rank,2,1)=5 and substr(sno_rank,2,1)=5
129 or substr(cno_rank,3,1)=5 and substr(sno_rank,3,1)=5
130 or substr(cno_rank,4,1)=5 and substr(sno_rank,4,1)=5
131 or substr(cno_rank,5,1)=5 and substr(sno_rank,5,1)=5) --13
132 and ( substr(hno_rank,2,1)=5 ) --14
133 and ( (substr(sno_rank,1,1)=3 and substr(dno_rank,2,1)=5) --15
134 or (substr(sno_rank,2,1)=3 and (substr(dno_rank,1,1)=5 or substr(dno_rank,3,1)=5))
135 or (substr(sno_rank,3,1)=3 and (substr(dno_rank,2,1)=5 or substr(dno_rank,4,1)=5))
136 or (substr(sno_rank,4,1)=3 and (substr(dno_rank,3,1)=5 or substr(dno_rank,5,1)=5))
137 or (substr(sno_rank,5,1)=3 and substr(dno_rank,4,1)=5 )
138 );
COUNTRY
---------
German |
|