title: Update column value based on Cummulative sum of other two column
body: <p>I have following table</p>
  <p><strong>Buffer</strong></p>
  <pre><code>| id    | from_Time     | To_time   | v1    | v2    | v3    | time Stamp            |
  |-----  |-----------    |---------  |----   |----   |----   |---------------------  |
  | 104   | 10            | 11        | 9     | 8     |       | 2020-12-02 11:03:01   |
  | 103   | 9             | 10        | 10    | 11    |       | 2020-12-02 10:03:01   |
  | 102   | 8             | 9         | 13    | 13    |       | 2020-12-02 09:03:01   |
  | 101   | 7             | 8         | 12    | 11    |       | 2020-12-02 08:03:01   |
  | 100   | 6             | 7         | 10    | 8     |       | 2020-12-02 07:03:01   |
  | 99    | 5             | 6         | 0     | 0     |       | 2020-12-02 06:03:01   |
  | 98    | 4             | 5         | 0     | 0     |       | 2020-12-02 05:03:01   |
  | 97    | 3             | 4         | 0     | 0     |       | 2020-12-02 03:03:15   |
  | 96    | 2             | 3         | 0     | 0     |       | 2020-12-02 04:03:02   |
  | 95    | 1             | 2         | 0     | 0     |       | 2020-12-02 02:03:01   |
  | 94    | 0             | 1         | 0     | 0     |       | 2020-12-02 01:03:00   |
  | 93    | 23            | 0         | 0     | 0     | 2     | 2020-12-02 00:03:00   |
  | 92    | 22            | 23        | 0     | 4     | 2     | 2020-12-01 23:03:01   |
  | 91    | 21            | 22        | 14    | 13    | 6     | 2020-12-01 22:03:00   |
  | 90    | 20            | 21        | 10    | 8     | 5     | 2020-12-01 21:03:00   |
  | 89    | 19            | 20        | 7     | 5     | 3     | 2020-12-01 20:03:01   |
  | 88    |               |           |       |       |       |                       |
  | 87    |               |           |       |       |       |                       |
  | 86    |               |           |       |       |       |                       |
  | 85    | 23            | 0         | 0     | 0     | 1     | 2020-12-01 01:03:00   |
  </code></pre>
  <p>I would like to write an update query to update the column v3.
  column V3 is calculated as following</p>
  <p>Previous Day value between 23 and 0  + cummulative total of colum V1 for today's date -  cummulative total of colum V2 for today's date</p>
  <p>Example for an ID 91</p>
  <p>cummulative total of V1 is 31
  cummulative toatl of V2 is 26
  Previous Day value between 23 and 0 is 1</p>
  <p>so the value of V3 for ID 91 equals 1+31-26 = 6</p>
  <p>I would like to write an update query with a where clause to update the data for an ID from 104 to 100.</p>
  <p>I am able to get a new value of V3 using following query</p>
  <pre><code>select   T1.id,
      T1.from_time,
      T1.To_time,
      T1.v1
       ,T1.v2
       ,T1.cumm_v1,
       T1.cumm_v2
       ,T1.cumm_v1-T1.cumm_v2 + (
         select v3 from Buffer where CAST([time Stamp] as DATE)  = '20201202' and from_time = 23 and To_time = 0) 
         as V3_New
  from (
  SELECT 
    id,
    from_time,
    To_time,
    v1,
    v2,
    [time Stamp]
      ,SUM(v1) OVER(ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS cumm_v1
      ,SUM(v2) OVER(ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS cumm_v2
  FROM Buffer where CAST([time Stamp]  as DATE)  = '20201202'
         ) as T1
  </code></pre>
  <p>I am getting problem to convert it into an update query.</p>
  <p><a href="http://sqlfiddle.com/#!18/abaa1/2" rel="nofollow noreferrer">http://sqlfiddle.com/#!18/abaa1/2</a></p>