今天学习到了新的知识,关于sum(col) over(order by col)的用法,
create table t1 (id number,chg number);
insert into t1 values(1,1);
insert into t1 values(2,2);
insert into t1 values(3,3);
insert into t1 values(4,4);
insert into t1 values(5,5);
select id,chg,sum(chg) over(order by id) sum_chg from t1;
ID CHG SUM_CHG
---------- ---------- ----------
1 1 1
2 2 3
3 3 6
4 4 10
5 5 15
是一个累加的关系,sum_chg=3 是2+1 sum_chg=6是3+2+1得到sum_chg=15是5+4+3+2+1得到
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12216142/viewspace-536538/ ,如需转载,请注明出处,否则将追究法律责任。