|
|
在我这里还是没有ORACLE快:
sqlite> .timer on
sqlite> with t(n) as (select 1 union all select n+1 from t where n<10000),
...> s as (select a.n
...> from t a,t b
...> where a.n >= 2*b.n
...> and a.n%b.n = 0
...> group by a.n
...> having sum(b.n) > a.n)
...> select max(gap) from ( select lead(n) over(order by n) - n as gap from s
)
...> ;
6
Run Time: real 11.334 user 11.310073 sys 0.015600
sqlite>
jsu@JSU12P> with t(n) as (select 1 from dual union all select n+1 from t where n<10000),
2 s as (select a.n
3 from t a,t b
4 where a.n >= 2*b.n
5 and mod(a.n,b.n) = 0
6 group by a.n
7 having sum(b.n) > a.n)
8 select max(gap) from ( select lead(n) over(order by n) - n as gap from s)
9 ;
MAX(GAP)
----------
6
Elapsed: 00:00:09.85
|
|