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
1.4m articles
1.4m replys
5 comments
57.0k users