Reputation: 157
I want to find the days difference and populate a new column in my target table. The difference is created by subtracting the previous date from current date.
Please find the attached screen shot for reference.
Thanks.
Upvotes: 0
Views: 1032
Reputation: 1158
Using LAG
function help you to get the previous row and DATEDIFF
to get the difference.
select
id,
function_id,
key,
pre_date,
datediff(pre_date, lag(pre_date, 1) over(order by id)) as days_difference
from
[Your_Table]
Upvotes: 1