加入收藏 | 设为首页 | 会员中心 | 我要投稿 鄂州站长网 (https://www.0711zz.com/)- 数据分析、网络、云渲染、应用安全、大数据!
当前位置: 首页 > 数据库 > Oracle > 正文

Oracle逐行相加

发布时间:2020-07-16 05:20:52 所属栏目:Oracle 来源:互联网
导读:有时候有这种需求,查出来的结果集要逐行相加。 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

有时候有这种需求,查出来的结果集要逐行相加。

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

(编辑:鄂州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读