Reputation: 540
i Get some Problem with SQL , the problem is find the Difference between two record not in the same row . i take picture of the Excel sheet to illustrate what i mean . i need to find the difference between the recoed n and n+1 , one by one .
Upvotes: 0
Views: 52
Reputation: 1269445
You want the lag()
function:
select t.*,
(t.admission_date_time - lag(t.admission_date_time) over (order by t.admission_date_time
) as diff
from table t;
This will fetch the value from the previous row.
Upvotes: 2