subscription_id | purchase_date | current_date | plan_end_date | date_diff |
---|---|---|---|---|
1111 | 01-04-2022 | 11-04-2022 | 14-04-2022 | 3 |
2222 | 02-04-2022 | 11-04-2022 | 09-04-2022 | -2 |
3333 | 06-04-2022 | 11-04-2022 | 11-04-2022 | 0 |
I am looking for the above answer but not getting. It's coming different answer if I use lag and lead function.
CASE
WHEN plan_end_date > cur_date THEN cur_date - LAG(plan_end_date) OVER (ORDER BY cur_date)
WHEN plan_end_date < cur_date THEN cur_date - LEAD(plan_end_date) OVER (ORDER BY cur_date)
WHEN plan_end_date = cur_date THEN NULL
END AS date_diff
here is the above condition I have used.