开发者

How to sum incrementaly in Oracle 8?

开发者 https://www.devze.com 2023-02-17 04:47 出处:网络
I need to do an incremental sum in Oracle. My situati开发者_如何学Pythonon is the following: RecordIDValue

I need to do an incremental sum in Oracle.

My situati开发者_如何学Pythonon is the following:

RecordID      Value

1            1
2            2
3            5
4            10

And I need to get something like this:

RecordID      Sum_incremental

1            (1)
2            (1 + 2)
3            (1 + 2 + 5)
4            (1 + 2 + 5 + 10)


The clues: self join and group by.

The solution:

select a.recordid, sum(b.value) sum_incremental from mytable a, mytable b
where b.recordid <= a.recordid group by a.recordid


select recordid, 
       sum(value) over (order by recordid)
from some_data
0

精彩评论

暂无评论...
验证码 换一张
取 消