OiO.lk Blog SQL Compute diff between values of same column depending on datetime?
SQL

Compute diff between values of same column depending on datetime?


I have a mssql db which looks like this:

id | price | date     |version 
1  | 10    |2020-06-01| 1
2  | 15    |2020-06-12| 2
3  | 4     |2020-06-03| 1
4  | 5     |2020-06-04| 2
5  | 5.5   |2020-06-10| 3

What I want to do is to compute the difference between first two rows. For example, I want to compute 15- 10. These are the values for 2020-06-01 and 2020-06-01.
How could I do this? I have tried several sql statements but without success.



You need to sign in to view this answers

Exit mobile version