您的位置:首页 > 数据库 > Oracle

oracle数据同比的时候除数为0该怎么处理

2015-11-19 15:53 711 查看


如图,我想同比每年对应月份的cr值,也就是,今年比上年的是增加了还是减少了,然后用得是lag over函数,我并没有深入的了解过这两个函数,然后最后的结果就是,因为cr里面存在0,所以,进行数据同比的时候会报错,提示,除数不能为0,请问这种情况该怎么处理,求各位大神能教教俺,有点着急,在线等~,跪谢

select

a.*,

nvl(round(a.cr/lag(a.cr) over(partition by month order by a.stat_date)*100,2)-100,'0')||'%' hb

from (

select

t.stat_date,

substr(t.stat_date,0,4) year,

substr(t.stat_date,5,2) month,

t.wccb wccb,

t.tjtb tjtb,

t.cj cj,

trunc(t.cj/t.wccb,4) cr

from

(

select

substr(to_char(t.created_date,'yyyyMMdd'),0,6) stat_date,

count(t.th_id) WCCB,

sum(decode(t.apply_date,null,0,1)) TJTB,

sum(decode(t.elis_policy_no,null,0,1)) CJ

from life_th_app_policy_info t

group by substr(to_char(t.created_date,'yyyyMMdd'),0,6)

order by substr(to_char(t.created_date,'yyyyMMdd'),0,6)

) t

) a
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: