oracle中国如何实现同比,Oracle分析函数实现报表功能(同比,环比,累计,基比)...

CREATE TABLE salaryByMonth

(

employeeNo varchar2(20),

yearMonth varchar2(6),

salary number

) ;

insert into SALARYBYMONTH (EMPLOYEENO, YEARMONTH, SALARY)

values (1, '200805', 500);

insert into SALARYBYMONTH (EMPLOYEENO, YEARMONTH, SALARY)

values (1, '200802', 150);

insert into SALARYBYMONTH (EMPLOYEENO, YEARMONTH, SALARY)

values (1, '200803', 200);

insert into SALARYBYMONTH (EMPLOYEENO, YEARMONTH, SALARY)

values (1, '200804', 300);

insert into SALARYBYMONTH (EMPLOYEENO, YEARMONTH, SALARY)

values (1, '200708', 100);

commit;

SELECT EMPLOYEENO

,YEARMONTH

,SALARY

,MIN(SALARY) KEEP(DENSE_RANK FIRST ORDER BY YEARMONTH) OVER(PARTITION BY EMPLOYEENO) FIRST_SALARY -- 基比分析 salary/first_salary

,LAG(SALARY, 1, 0) OVER(PARTITION BY EMPLOYEENO ORDER BY YEARMONTH) AS PREV_SAL -- 环比分析,与上个月份进行比较

,LAG(SALARY, 12, 0) OVER(PARTITION BY EMPLOYEENO ORDER BY YEARMONTH) AS PREV_12_SAL -- 同比分析,与上个年度相同月份进行比较

,SUM(SALARY) OVER(PARTITION BY EMPLOYEENO, SUBSTR(YEARMONTH, 1, 4) ORDER BY YEARMONTH RANGE UNBOUNDED PRECEDING) LJ --累计值

FROM SALARYBYMONTH

ORDER BY EMPLOYEENO

,YEARMONTH

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值