Sum over group
<p>Hello,<br>
<br>
I have a table <font face="Courier New">t1</font> with the following data:<br>
<br><font face="Courier New">ID_NUMBER VALUE1<br>1 0<br>2 4<br>3 4<br>4 -2<br>5 4<br>6 6<br>7 -3<br>8 -2<br>9 -2<br>10 2<br>
11 4</font><br>
<br>I would like to show an accumulative sum of negative value1 only, restarting
the sum on every new negative group, ordered by id_number. So far, when I use the
<font face="Courier New">DECODE(SIGN(value1), -1, SUM(DECODE(SIGN(value1), -1,
value1, 0)) OVER(ORDER BY id_number)) </font>function, the accumulative sum
considers all the negative values:</p>
<p><font face="Courier New">ID_NUMBER VALUE1 MY_SUM<br>1 0
<br>2 4
<br>3 4
<br>4 -2
-2<br>5 4
<br>6 6
<br>7 -3
-5<br>8 -2
-7<br>9 -2
-9<br>10 2
<br>
11 4 <br>
</font><br>However, I would to show my sum like this:</p>
<p><font face="Courier New">ID_NUMBER VALUE1 MY_SUM<br>1 0
<br>2 4
<br>3 4
<br>4 -2
-2<br>5 4
<br>6 6
<br>7 -3
-3<br>8 -2
-5<br>9 -2
-7<br>10 2
<br>
11 4
</font><br><br>Is there a way to accomplish this using analytic functions only?<br>
<br>Thanks in advance,<br><br>Luis</p>