|
with tmp1 as(select rownum as p from dual connect by rownum <= 7),
tmp2 as(select a.p as x,b.p as y from tmp1 a, tmp1 b),
tmp3 as(
select
a.x as a_x, a.y as a_y,
b.x as b_x, b.y as b_y,
c.x as c_x, c.y as c_y,
d.x as d_x, d.y as d_y
from tmp2 a, tmp2 b, tmp2 c, tmp2 d
where
abs(a.x-b.x) <> abs(a.y-b.y) and abs(a.x-c.x) <> abs(a.y-c.y) and abs(a.x-d.x) <> abs(a.y-d.y)
and abs(b.x-c.x) <> abs(b.y-c.y) and abs(b.x-d.x) <> abs(b.y-d.y)
and abs(c.x-d.x) <> abs(c.y-d.y)
and c.y <> d.y
and b.y <> c.y and b.y <> d.y
and a.y <> b.y and a.y <> c.y and a.y <> d.y
and a.x < b.x and b.x < c.x and c.x < d.x)
--
select
'('||a_x||','||a_y||')' as P1,
'('||b_x||','||b_y||')' as P2,
'('||c_x||','||c_y||')' as P3,
'('||d_x||','||d_y||')' as P4
from
(select b.a_x,b.b_x,b.c_x,b.d_x,b.a_y,b.b_y,b.c_y,b.d_y from tmp3 b
minus
select
b.a_x,b.b_x,b.c_x,b.d_x,b.a_y,b.b_y,b.c_y,b.d_y
from tmp2 a, tmp3 b
where abs(a.x-b.a_x)<>abs(a.y-b.a_y) and abs(a.x-b.b_x)<>abs(a.y-b.b_y)
and abs(a.x-b.c_x)<>abs(a.y-b.c_y) and abs(a.x-b.d_x)<>abs(a.y-b.d_y)
and a.x not in (b.a_x,b.b_x,b.c_x,b.d_x)
and a.y not in (b.a_y,b.b_y,b.c_y,b.d_y)
group by b.a_x,b.b_x,b.c_x,b.d_x,b.a_y,b.b_y,b.c_y,b.d_y)
-- Result
P1 P2 P3 P4
1 (1,2) (2,6) (4,1) (5,5)
2 (1,6) (2,2) (4,7) (5,3)
3 (1,4) (2,1) (5,5) (6,2)
4 (1,4) (2,7) (5,3) (6,6)
5 (2,2) (3,5) (6,1) (7,4)
6 (2,6) (3,3) (6,7) (7,4)
7 (3,3) (4,7) (6,2) (7,6)
8 (3,5) (4,1) (6,6) (7,2)
-- 8 rows selected in 0.563 seconds |
|