oracle用sum函数实现累加
[html] ====================Question========================= jmbdat dayt y mon 27-9月 -07 2033.2 2007 200709 28-9月 -07 2750.28 2007 200709 29-9月 -07 2885.68 2007 200709 30-9月 -07 2556.68 2007 200709 01-10月-07 2903.04 2007 200710 02-10月-07 1002.96 2007 200710 03-10月-07 1038.24 2007 200710
对上边的表用sql处理下 变成下面的
jmbdat dayt y mon mont 27-9月 -07 2033.2 2007 200709 2033.2 28-9月 -07 2750.28 2007 200709 4783.28 29-9月 -07 2885.68 2007 200709 7669.16 30-9月 -07 2556.68 2007 200709 20225.84 01-10月-07 2903.04 2007 200710 2903.04 02-10月-07 1002.96 2007 200710 3906 03-10月-07 1038.24 2007 200710 4944.24
该怎么做啊?
==================Solution=========================
SQL:
select tt.*,
sum(tt.dayt) over (partition by tt.mon order by tt.jmbdat,tt.y,tt.mon) as sum_dayt
from tablename tt;
Result :
JMBDAT DAYT Y MON SUM_DAYT
----------- ---------- ---------- ------ ----------
2007-9-27 2033.2 2007 200709 2033.2
2007-9-28 2750.28 2007 200709 4783.48
2007-9-29 2885.68 2007 200709 7669.16
2007-9-30 2556.68 2007 200709 10225.84
2007-10-1 2903.04 2007 200710 2903.04
2007-10-2 1002.96 2007 200710 3906
2007-10-7 1038.24 2007 200710 4944.24
7 rows selected