Page 1 of 1

Running Total in Query

Posted: Tue Apr 25, 2006 2:21 am
by omerjaved100
SELECT ename , deptno , sal ,
SUM(sal)
OVER (order by ename) "Running Total"
from emp
order by ename;

ENAME DEPTNO SAL Running Total
---------- ---------- ---------- -------------
ADAMS 20 1100 1100
ALLEN 30 1600 2700
BLAKE 30 2850 5550
CLARK 10 2450 8000
FORD 20 3000 11000
JAMES 30 950 11950
JONES 20 2975 14925
KING 10 5000 19925
MARTIN 30 1250 21175
MILLER 10 1300 22475
SCOTT 20 3000 25475



Regards,
M.Omer Javed
ERP Technical Consultant
Mob:+923214647529/ +923004479693

Posted: Tue Apr 25, 2006 7:22 am
by mirza_rehan
Assalam-o-Alaikum,

Yes it is good query but it is not back word compatable i mean it is not compatable with older version of oracle.

Use this query for backword compatabity

select a.EmpNo,a.EName,a.Sal,sum(b.sal)
from scott.emp b, scott.emp a
where b.rowid <= a.rowid
group by a.RowID,a.EmpNo,a.EName,a.sal

thanks & regards
R E H A N M I R Z A
O.C.P. Developer Rel. 2 & 6 / 6i
System Analyst / Senior Oracle Developer
Union Exports (Pvt.) Ltd.
Mob.: +92-304-2120807

When ever you pray
Please remember me and my family