oracle如何实现累乘,由复合指标计算引起的oracle累乘

项目中复合指标由配置好的基础指标公式解析后存到如下一张表中:

--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

)

复合指标1:(1001+1003)/(1002-1004)=-12

复合指标2:1006*1007/(2011+2022)=1.5

复合指标3:1009*1010/1011=0.5

6d7e996551e51a2c632bc50085f35dc7.png

--单独除法关系的指标

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

网上查找相关资料表明,

http://blog.sina.com.cn/s/blog_63f3c0b201015gh9.htmloracle的累乘用法已经被很多人使用过啦。

exp(y)

【功能】返回e的y次幂(e为数学常量)

【参数】y,数字型表达式

ln(y)

【功能】返回e为底的自然对数。

由于ln对应的y参数仅可为正数,所以如下进行连乘的方法只能针对正数,不包含负数哦~

--先乘后除指标【累乘算法: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 in (2,3)

group by t.complexid

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值