title: calculation of points for each student. two columns' calculations are based each other
body: <p>I want to calculate the remaining points in sql server using cte or any other method</p>
  <p>in calculation formula : see the attatched picture.
  total points 100
  i have used row Count using cte for each student.</p>
  <pre class="lang-none prettyprint-override"><code>Row_no  |st_id  |plenty |weekBonus  |weekbenformula |remaining_Points
  1       |1      |5      |0          |0              |95
  2       |1      |3      |2          |2              |94
  3       |1      |2      |0          |0              |92
  4       |1      |3      |2          |6              |95
  5       |1      |1      |1          |1              |95
  6       |1      |3      |1          |1              |93
  7       |1      |2      |0          |0              |91
  </code></pre>
  <p>Excel example picture is attached.
  <a href="https://i.stack.imgur.com/3FY0X.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3FY0X.jpg" alt="in excel is it very easy to solve." /></a></p>
  <p>first row calculation for st_id 1: 100 -5 +0= 95</p>
  <p>second row calculation for st_id1: 95 - 3 +2=94     here i have to take the previous remaining points. and so on...</p>
  <p>or any other solution for this problem.</p>