日期:2014-05-17 浏览次数:20936 次
create or replace  table t(group,score);
create or replace table  u(group,num);
insert into t values ('A',500);
insert into t values ('B',500);
insert into t values ('C',300);
insert into u values ('A',20);
insert into u values ('B',20);
insert into u values ('C',8);
select a.group,sn,a.rn,b.ct,decode(a.rn,1,20/ct
                                        2,10/ct) sal 
    from
     (select group, score/num sn,dense_rank()over(order by score/num desc) rn  from t,u  where t.group=u.group) a,
     (select rn,count(*) ct from 
     (select group, score/num sn,dense_rank()over(order by score/num desc) rn from t,u where t.group=u.group) group by rn) b   
where a.rn=b.rn
group     sn   rn    ct    sal
------  -----  ----  ----  ---
C         37.5  1      1     20
B         25    2      2      5
A         25    2      2      5