Oracle逐行相加
发布时间:2020-12-12 16:36:59 所属栏目:百科 来源:网络整理
导读:有时候有这种需求,查出来的结果集要逐行相加。 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
有时候有这种需求,查出来的结果集要逐行相加。 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(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |