select a.date,a.amt,b.aAMT from table a, (select date,sum(amt) AMT from table where date < '') b where a.date = b.date and a.date <''
re : rxzhu(思维) 谢谢参与,但答案不能通过
如果你是Oracle9.0以上的版本, 可以用sum与Over来完成: 给你一个例了: SELECT manager_id, last_name, salary, SUM(salary) OVER (PARTITION BY manager_id ORDER BY salary RANGE UNBOUNDED PRECEDING) l_csum FROM employees;MANAGER_ID LAST_NAME SALARY L_CSUM ---------- --------------- ---------- ---------- 100 Mourgos 5800 5800 100 Vollman 6500 12300 100 Kaufling 7900 20200 100 Weiss 8000 28200 100 Fripp 8200 36400 100 Zlotkey 10500 46900 100 Raphaely 11000 68900 100 Cambrault 11000 68900 100 Errazuriz 12000 80900 . . . 149 Taylor 8600 30200 149 Hutton 8800 39000 149 Abel 11000 50000 201 Fay 6000 6000 205 Gietz 8300 8300 King 24000 24000
select a.date,amt , (select sum(b.amt) from (select date,rownum as num,amt from table order by date) b where b.num <= a.num ) from (select date,rownum as num,amt from table order by date) a ;
from table a,
(select date,sum(amt) AMT
from table
where date < '') b
where a.date = b.date
and a.date <''
谢谢参与,但答案不能通过
给你一个例了:
SELECT manager_id, last_name, salary,
SUM(salary) OVER (PARTITION BY manager_id ORDER BY salary
RANGE UNBOUNDED PRECEDING) l_csum
FROM employees;MANAGER_ID LAST_NAME SALARY L_CSUM
---------- --------------- ---------- ----------
100 Mourgos 5800 5800
100 Vollman 6500 12300
100 Kaufling 7900 20200
100 Weiss 8000 28200
100 Fripp 8200 36400
100 Zlotkey 10500 46900
100 Raphaely 11000 68900
100 Cambrault 11000 68900
100 Errazuriz 12000 80900
.
.
.
149 Taylor 8600 30200
149 Hutton 8800 39000
149 Abel 11000 50000
201 Fay 6000 6000
205 Gietz 8300 8300
King 24000 24000
(select sum(b.amt) from
(select date,rownum as num,amt from table order by date) b
where b.num <= a.num )
from (select date,rownum as num,amt from table order by date) a
;
建义楼主update oracle