17,382
社区成员




-- lag 函数
SQL> create table test(y int , sale int) ;
Table created
SQL> insert into test
2 select 2010 + rownum,rownum * 100 from dual connect by rownum <= 5;
5 rows inserted
SQL> select y, sale, sale / lag(sale,1) over(order by y) - 1
2 from test ;
Y SALE SALE/LAG(SALE,1)OVER(ORDERBYY)
---------- ---------- ------------------------------
2011 100
2012 200 1
2013 300 0.5
2014 400 0.333333333333333
2015 500 0.25
SQL> drop table test purge ;
Table dropped
SQL>