|
# 4
--method 1:
SQL>
SQL> with t as (select level n from dual connect by level<=20),
2 s as (select substr(sys_connect_by_path(n,','),2) path
3 from t
4 where level = 5
5 connect by nocycle prior n < n ),
6 r as (select path,regexp_substr(path,'[^,]+',1,level) v
7 from s
8 connect by prior path = path
9 and level <= regexp_count(path,',')+1
10 and prior dbms_random.value is not null),
11 p as (
12 select count(distinct a.path) cnt
13 from (
14 select path,v,
15 count(case when v <=10 then 1 end) over(partition by path) lt,
16 count(case when v >=11 then 1 end) over(partition by path) gt
17 from r
18 ) a
19 where (lt = 5 and gt = 0) or (lt=0 and gt=5)
20 ),
21 q as (
22 select cnt,(select count(*) from s) as total_cnt from p),
23 f(total_cnt,cnt) as ( select total_cnt,cnt from q
24 union all
25 select greatest(total_cnt - cnt,cnt),least(total_cnt - cnt,cnt)
26 from f
27 where total_cnt <> cnt)
28 select q.cnt/f.cnt||'/'||q.total_cnt/f.cnt as res
29 from q,f
30 where f.total_cnt = f.cnt
31 /
RES
--------------------------------------------------------------------------------
21/646 |
|