有时候有这种需求,查出来的结果集要逐行相加。
create table t
( id number,value number ); insert into t values(1,10); insert into t values(2,10); insert into t values(3,20); insert into t values(4,20); insert into t values(5,30); insert into t values(6,30); commit; sql> select * from t; ID VALUE ---------- ---------- 1 10 2 10 3 20 4 20 5 30 6 30 sql> select id,value,sum(value)over(order by id asc rows between unbounded preceding and current row) s_value from t; ID VALUE S_VALUE ---------- ---------- ---------- 1 10 10 2 10 20 3 20 40 4 20 60 5 30 90 6 30 120