How to Add or subtract rows of one columns this example in sql 2014? I want to update column price in table but I can't.

Sutract price id = 1304  and n = 1  and price with  id = 1304 and n= 2 

(price with id =1307 and n = 1 ) - (price with  id = 1307 and n= 2) 
and 
(price id =1307 and n = 1 - price with id = 1307 and n= 3) 
and 
(price id = 1307 and n = 1 - price with id = 1307 and n= 4) 
and
(price id = 1307 and n = 1 - price with id = 1307 and n= 5)


TBL_Price now :

    |     id    |N |      Price    | 
--------------------------------------------------------------------------
    |      1304 | 1|         32000 |
    |      1304 | 2|         28000 |
    |      1305 | 1|         42000 |
    |      1306 | 1|         52000 |
    |      1306 | 2|         38000 |
    |      1306 | 3|         63000 |
    |      1306 | 4|         52000 |
    |      1307 | 1|         15000 |
    |      1307 | 2|         12000 |
    |      1307 | 3|         15000 |
    |      1307 | 4|         17000 |
    |      1307 | 5|         20000 |


The result is:

    |     id    |N |      Price    | 
--------------------------------------------------------------------------
    |      1304 | 1|         32000 |
    |      1304 | 2|         -4000 |
    |      1305 | 1|         42000 |
    |      1306 | 1|         52000 |
    |      1306 | 2|        -14000 |
    |      1306 | 3|        +11000 |
    |      1306 | 4|         0     |
    |      1307 | 1|         15000 |
    |      1307 | 2|         -3000 |
    |      1307 | 3|         0     |
    |      1307 | 4|         +2000 |
    |      1307 | 5|         +5000 | 


try:

SELECT [ID]
    ,[N]
     ,[Price]
  ,coalesce((select Price - Price where ID = ID and N = 2),price)
 FROM [dbo].[Tbl_Price]
OK, so let's rephrase:  


  for each id, if N=1, return price, else, return price for N=1 for the
  same id minus current price.


You can try this ugly:

select *, iif(tt.N = 1, t.price, isnull(tt.price, 0) - t.price)
from my_table t
left join (select * from my_table) tt on t.id = tt.id
where t.N = 1


Or a trendier version using first_value statement (starting from version 2012) and assuming we have, for all id, a row with N=1:

select *, iif(N=1,price, price - first_value(price) over(partition by id order by N) )
from my_table