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