Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: A typical query
<venkatprakash_at_my-deja.com> wrote in message news:7pk30n$37f$1_at_nnrp1.deja.com...
> I have a typical problem to solve.
>
> IMPORTANT: I need to write a single SQL statement to solve the below
> problsm:
>
> Finding the cumulative value of n records. For eg
>
> sal
> ===
> 10
> 20
> 30
>
> The answer should be 10+(10+20)+(10+20+30)+...
>
> Can anybody give me a tip, please.
>
> Thanks
>
> V Prakash
V Prakash, You didn't describe your problem and contents clearly. What's is the logical order in your table? Is what you want is just one number 10+(10+20)+(10+20+30)+...? If so, assume your logical order is empno, then
select sum(b.sal)
from emp a, emp b
where a.empno>=b.empno;
If you want to list accumulative sum in each row, then
select a.empno, a.sal, sum(b.sal)
from emp a, emp b
where a.empno>=b.empno
group by a.empno, a.sal
Received on Sun Aug 22 1999 - 05:00:55 CDT
![]() |
![]() |