日期:2014-05-16 浏览次数:20473 次
--Create table create table TESTRRT ( complexid NUMBER not null,--复合指标id basicid VARCHAR2(20) not null,--基础指标id chu VARCHAR2(20),--除法标示(a为分子,b为分母) plus VARCHAR2(20),--乘法标示 direction NUMBER,--计算方向(1为正2为负) value NUMBER )

--单独除法关系的指标
select t.complexid,
       decode(sum(case
                    when t.chu = 'b' and t.direction = 1 then
                     t.VALUE
                    when t.chu = 'b' and t.direction = 2 then
                     -t.VALUE
                  end),
              0,
              0,
              sum(case
                    when t.chu = 'a' and t.direction = 1 then
                     t.VALUE
                    when t.chu = 'a' and t.direction = 2 then
                     -t.VALUE
                  end) / sum(case
                               when t.chu = 'b' and t.direction = 1 then
                                t.VALUE
                               when t.chu = 'b' and t.direction = 2 then
                                -t.VALUE
                             end))             
  from testrrt t
 where t.complexid = 1
 group by t.complexid
--先乘后除指标【累乘算法:exp(ln(a)+ln(b)+ln(c))=a*b*c】
select t.complexid,
decode(exp(sum(ln(case
                      when t.plus = 'p' and t.chu = 'b' then
                       t.value
                    end))),0,0,exp(sum(ln(case
                      when t.plus = 'p' and t.chu = 'a' then
                       t.value
                    end)))/sum(case
                      when t.plus is null and t.chu = 'b' then
                       t.value
                    end)
                    )
          mvalues
    from testrrt t
   where t.complexid = 3
   group by t.complexid