最近需要做一个统计数据的报表,然后遇到了当数据为0的时候怎么进行数据同比
一直提示除数为0,我的sql粘贴如下,在线等答案~
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