oracle同环比计算


with temp as
(select to_char(jsrq , 'yyyymm') as month, sum(zfy ) as num
from hip_mz_ys a, JCXX_JG b, jcxx_ks c, jcxx_ry d
where a.jg_id = b.yljgdm
and a.bm_id = c.ksid
and a.ry_id = d.ylryid
group by to_char(jsrq , 'yyyymm'))
select month,
round(nvl(num * 100 / (select num
from temp t1
where t1.month = (substr(t.month, 1, 4) - 1) ||
substr(t.month, -2)),
0),
2) as 同比,
round(nvl(num * 100 /
(select num
from temp t2
where t2.month =
to_char(to_date(t.month, 'yyyymm') - 1, 'yyyymm')),
0),
2) as 环比
from temp t
order by month asc


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM