トップページに戻る    次のSQLパズルへ    前のSQLパズルへ

11-12 引き算でGO

SQLパズル

最初に四角形を書きます。
下の図のように、その4つの頂点の上に、それぞれ適当な数字を書きます。


次に4つの辺の中点を結んだ四角形を書いて、 その頂点に、それぞれ隣り合った数字の差を書き入れます。
さらに、今書いた四角形の中点を結んだ四角形を書いて、 その頂点に、それぞれ隣り合った数字の差を書き入れます。
同じ操作を続けると、
上の図のように、4つの数字が全部「0」になってしまします。 今回は、4回で、全部「0」になりましたが、 これをできるだけ「0」にしないように続けて下さい! 目標10回以上です!

引き算でGO


SQL

select List from(
select abs(a-b) as a,abs(b-c) as b,abs(c-d) as c,abs(d-a) as d,List from(
select abs(a-b) as a,abs(b-c) as b,abs(c-d) as c,abs(d-a) as d,List from(
select abs(a-b) as a,abs(b-c) as b,abs(c-d) as c,abs(d-a) as d,List from(
select abs(a-b) as a,abs(b-c) as b,abs(c-d) as c,abs(d-a) as d,List from(
select abs(a-b) as a,abs(b-c) as b,abs(c-d) as c,abs(d-a) as d,List from(
select abs(a-b) as a,abs(b-c) as b,abs(c-d) as c,abs(d-a) as d,List from(
select abs(a-b) as a,abs(b-c) as b,abs(c-d) as c,abs(d-a) as d,List from(
select abs(a-b) as a,abs(b-c) as b,abs(c-d) as c,abs(d-a) as d,List from(
select abs(a-b) as a,abs(b-c) as b,abs(c-d) as c,abs(d-a) as d,List from(
select a.Val as a,b.Val as b,c.Val as c,d.Val as d,
to_char(a.Val) || ',' || to_char(b.Val) || ',' || to_char(c.Val) || ',' || to_char(d.Val) as List
  from (select RowNum as Val from all_catalog where RowNum <= 15) a,
       (select RowNum as Val from all_catalog where RowNum <= 15) b,
       (select RowNum as Val from all_catalog where RowNum <= 15) c,
       (select RowNum as Val from all_catalog where RowNum <= 15) d
 where a.Val <= c.Val and b.Val <= d.Val
   and a.Val <= b.Val)
where 0!= any(a-b,b-c,c-d,d-a))
where 0!= any(a-b,b-c,c-d,d-a))
where 0!= any(a-b,b-c,c-d,d-a))
where 0!= any(a-b,b-c,c-d,d-a))
where 0!= any(a-b,b-c,c-d,d-a))
where 0!= any(a-b,b-c,c-d,d-a))
where 0!= any(a-b,b-c,c-d,d-a))
where 0!= any(a-b,b-c,c-d,d-a))
where 0!= any(a-b,b-c,c-d,d-a))
where 0 = all(a-b,b-c,c-d,d-a);


解説

インラインビューで差を求めてます。