Oracle 同比环比

环比:与上个统计周期相比的变化比。 例如,2021年1月份与2020年12月份相比较称其为环比。
同比:与去年同时期相比的变化比。 例如,2021年1月份与2020年1月份相比较称其为同比。

同比增长率=(本期数-同期数)/同期数100% 指和去年同期相比较的增长率。
环比增长率=(本期数-上期数)/上期数100% 反映本期比上期增长了多少。

除:注意分母不能为零。避免会出错
参考文章:
https://www.oracletutorial.com/oracle-analytic-functions/oracle-lag/
http://www.voycn.com/article/oracledelagheleadfenxihanshu
http://www.xiayou.net/oracle/4616.html

1:
select lag(money, 1, 1) over(partition by t.dept order by t.month ) last_money ,
round(money /
(lag(money, 1, 1)
over(partition by t.dept order by t.month )) * 100 - 100,
0) last_money

from t_table t
2:
/* select

(select decode(a.last_month ,0,0,round( (a.money- a.last_month ) / a.last_month ,2)) hunabilv
from (select id, money, lag(money , 1, 0) over(partition by b.dept order by b.month ) last_month from dept_table b ) a where a. id = t.id) last_month_aomunt_confirmed

from t_table t;
*/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值