I have a table which contains two columns Id and date column where there are multiple rows for each IDs. For example ID 2034 is repeating 4 times and ID 2345 is repeating 6 times, now for each ID, I need to create days_diff column where i want to compare first row date with second row date then first row date with third row date and when the difference is greater than 21 days then compare next row date with previous row date instead of first row date.
Final Data should be like this:
ID Date days_diff
2034 2022-01-01 -
2034 2022-01-18 17
2034 2022-01-24 23
2034 2022-01-26 02
2035 2022-02-01 -
2035 2022-02-13 12
2035 2022-03-13 28
2035 2022-03-16 03