查询:
with t as
(select rownum id, column_value value from table(sys.odcinumberlist (1,2,3,4.5,4.6,7,10)))
select t.*,
last_value(value) over (order by value range between unbounded preceding and 1 preceding) l1,
last_value(value) over (order by value rows between unbounded preceding and 1 preceding) l2
from t;
结果:
1 1
2 2 1 1
3 3 2 2
4 4.5 3 3
5 4.6 3 4.5
6 7 4.6 4.6
7 10 7 7
有没有大佬解释一下右边的那个3是怎么来的,最好能具体一点的说下值怎么来的,感谢感谢。
又比如取前2行:
with t as
(select rownum id, column_value value from table(sys.odcinumberlist (1,2,3,4.5,4.6,7,10)))
select t.*,
last_value(value) over (order by value range between unbounded preceding and 2 preceding) l1,
last_value(value) over (order by value rows between unbounded preceding and 2 preceding) l2
from t;
1 1
2 2
3 3 1 1
4 4.5 2 2
5 4.6 2 3
6 7 4.6 4.5
7 10 7 4.6
这里的这个2是怎么来的呢