I need to do partition on aa bb cc columns order by date and need results like if the difference is more than 60 days in consecutive rows. I tried with datediff(date,lag()) but not getting expected results.
Assuming date is a datetime type column, you can use below code - CASE when datediff(date,lag(Date, 1, 0) over (order by Date) ) >60 then 1 else 0 END diff_gt_60
CASE when datediff(date,lag(Date, 1, 0) over (order by Date) ) >60 then 1 else 0 END diff_gt_60
2.1m questions
2.1m answers
60 comments
57.0k users