Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: A typical query

Re: A typical query

From: fump <fumi_at_tpts5.seed.net.tw>
Date: 22 Aug 1999 10:00:55 GMT
Message-ID: <7pohon$t95$5@news.seed.net.tw>

<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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US