|
SQL>
SQL> with t as (select level n from dual where level>=10 connect by level <100),
2 s as (
3 select a.n + b.n, count(*)*count(*) p, (90*89/2)*(90*89/2) q
4 from t a, t b
5 where a.n < b.n
6 group by a.n + b.n
7 order by a.n + b.n),
8 x as (
9 select q ,sum(p) as p
10 from s
11 group by q),
12 y(m,n,cnt) as
13 (select q m,p n, 1 cnt from x
14 union all
15 select case when m<n then n else m-n end,case when m<n then m else n end, cnt+1
16 from y
17 where cnt<=200) --这里如果写 n<=0 出现了循环, 所以就猜了个步数作为退出条件.
18 select q/z.m,p/z.m
19 from x,(select m from y where n = 0 and rownum=1) z
20 /
Q/Z.M P/Z.M
---------- ----------
1069335 7967
SQL> |
|