Difference in Value between latest two rows? I have a table as follows:

Id  |   Name    |   Value   |   RegisterDate
--------------------------------------------------
1   |   name1   |   11      |   2018-01-01
2   |   name2   |   12      |   2018-01-02
3   |   name3   |   13      |   2018-01-03
4   |   name4   |   14      |   2018-01-04
5   |   name5   |   15      |   2018-02-05
6   |   name6   |   16      |   2018-02-06
7   |   name7   |   17      |   2018-02-07
8   |   name8   |   18      |   2018-02-08


I want a query to get different value between two latest value fields Order By Desc RegisterDate?

In above sample query result is = 18 - 17 = 1
Another way using lag() to access the previous value and TOP to only get the latest.

SELECT TOP(1)
       value - lag(value, 1, 0) OVER (ORDER BY registerdate)
       FROM elbat
       ORDER BY registerdate DESC;