title: How to find the cumulative difference between two rows and display it accordingly?
body: <p>Thank you in advance.</p>
  
  <p>I have a table: </p>
  
  <pre><code>ID | NAME    | Value
  ---+---------+------------- 
   1 | ABC     | 1987698.987
   2 | DEF     | 1987870.987
   3 | GHI     | 1987990.987
   4 | JKL     | 1988200.987
  </code></pre>
  
  <p>Output: </p>
  
  <pre><code>ID | NAME  | Value       | Cumulative_difference
  ---+-------+-------------+----------------------
   1 | ABC   | 1987698.987 |      0  
   2 | DEF   | 1987870.987 |    172
   3 | GHI   | 1987990.987 |    120
   4 | JKL   | 1988200.987 |    210
  </code></pre>
  
  <p>The calculation for cumulative_difference is = (1987870.987 - 1987698.987 ) else '0'</p>
  
  <p>This is the query I have used but I am getting negative values:</p>
  
  <pre><code> select 
       id, name, value, value 
       -LAG(value, 1, 1) over (partition by name order by id)
   from 
       table1
  </code></pre>
  
  <p>Any help would be appreciated.</p>
  
  <p>I am using SQL Server 2012.</p>
  
  <p>Thank you</p>