Retornando um somatório acumulativo

Veja nesta dica como retornar um somatório acumulativo no Oracle.

<PRE><BR><STRONG>Retornando um somatório acumulativo </STRONG></FONT></PRE><PRE>O script abaixo retorna a soma acumulativa para uma determinada coluna. <BR></FONT>Este exemplo usa a coluna SAL da tabela EMP:</FONT></PRE><PRE>SQL> select b.sal,sum(a.sal) as cum_sal<BR>2 from emp a,emp b<BR>3 where a.rowid <= b.rowid<BR>4 group by b.rowid,b.sal<BR>5 /</FONT></PRE><PRE>      SAL    CUM_SAL<BR>---------  ---------<BR>      800        800<BR>     1600       2400<BR>     1250       3650<BR>     2975       6625<BR>     1250       7875<BR>     2850      10725<BR>     2450      13175<BR>     3000      16175<BR>     5000      21175<BR>     1500      22675<BR>     1100      23775</FONT></PRE><PRE>      SAL    CUM_SAL<BR>---------  ---------<BR>      950      24725<BR>     3000      27725<BR>     1300      29025</FONT></PRE><PRE>14 rows selected.</FONT> </FONT></FONT>

Artigos relacionados