title: How to do Diagonal subtraction of result and current value
body: <p>I have a product table and I want to do a zigzag subtraction with price column</p>
  
  <p>I have tried with below query but it does not work for me</p>
  
  <pre><code>SELECT price
  ,price - (SELECT COALESCE(lag(price) OVER (ORDER BY ProductID),price)  AS PayableInQuarter  
  FROM @Products WHERE ProductID=1) from @Products
  </code></pre>
  
  <p>Code to create table</p>
  
  <pre><code>DECLARE @Products TABLE (ProductID INT, ProductName VARCHAR(20), Price int)
  
  INSERT INTO @Products VALUES (1, 'A', 1000)
  INSERT INTO @Products VALUES (2, 'B', 5000)
  INSERT INTO @Products VALUES (3, 'C', 9000)
  INSERT INTO @Products VALUES (4, 'E', 12000)
  
  SELECT * FROM @Products
  </code></pre>
  
  <p>Expected output as below</p>
  
  <pre><code>| ProductId | ProductName | Price | Difference |
  |-----------|-------------|-------|------------|
  |         1 |           A |  1000 |       1000 |
  |         2 |           B |  5000 |       4000 |
  |         3 |           C |  9000 |       5000 |
  |         4 |           E | 12000 |       7000 |
  </code></pre>