oracle求同比,环比函数(LAG与LEAD)的详解建站知识
导读:1建站知识本篇文章是对oracle求同比,环比函数(LAG与LEAD)进行了详细的分析介绍,需要的朋友参考下网站建设网站建设多少钱。
Lag和Lead函数可以在一次查询中取出同一字段的前N行的数据和后N行的值。这种操作可以使用对相同表的表连接来实建设网站公司现,不过使用LAG和LEAD有更高的效率。
复制代码 代码如下:
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
相关网站建设网站建设多少钱。声明: 本文由我的SEOUC技术文章主页发布于:2023-05-23 ,文章oracle求同比,环比函数(LAG与LEAD)的详解建站知识主要讲述详解,函数,oracle求同比,环比函数(LAG与LEAD)网站建设源码以及服务器配置搭建相关技术文章。转载请保留链接: https://www.seouc.com/article/web_5955.html