title: conditional sum in select statement
body: <p>I’m trying to do conditional sum in select statement a table but I can’t think of way to do so.</p>
  
  <p>The sum should keep on going until it hits a reset flag in the table.</p>
  
  <p>Increment values need to be set to 0 when reset flag is hit(1) and it should start summing again from next row.</p>
  
  <p>Please have a look at the data structure I want to select from my a big table</p>
  
  <pre><code>ID  Value  ValueIncrement                   ResetFlag
  1     2          2                              0   
  2     3          5  (2+3)                       0
  3     9          14 (2+3+9)                     0   
  4     6          20 (2+3+9+6)                   0
  5     3          23 (2+3+9+6+3)                 0
  6     1          24 (2+3+9+6+3+1)               0
  7     2          26 (2+3+9+6+3+1+2)             0
  8     0          26 (2+3+9+6+3+1+2+0)           0
  9     2          30 (2+3+9+6+3+1+2+0+2)         1
  10    4          4                              0   
  11    5          9 (4+5)                        0
  12    3          12 (4+5+3)                     0   
  13    6          18 (4+5+3+6)                   0
  14    7          25(4+5+3+6+7)                  0
  15    4          29(4+5+3+6+7+4)                0
  16    7          36(4+5+3+6+7+4+7)              0
  17    9          ‭45‬(4+5+3+6+7+4+7+9)          0   
  18    2          47(4+5+3+6+7+4+7+9+2)          0
  19    1          48(4+5+3+6+7+4+7+9+2+1)        0
  20    1          49(4+5+3+6+7+4+7+9+2+1+1)      1
  </code></pre>
  
  <p>I tried few things but I couldn’t get it to work the way I need, any help or suggestion would be much appreciated. </p>