Sobes.tech
Middle

Ostateczny wynik: | customer_id | gap_days | |-------------|----------| | 1 | 123 | | 2 | 120 | z cte jako( wybierz order_id, customer_id, order_dt, lag(order_dt) over(partition by customer_id order by order_dt) jako prev_order_ft, datediff(day, prev_order_ft, order_dt) jako gap_days z Orders ) wybierz customer_id, max(gap_days) jako gap_days z cte gdzie gap_days > 60 grupuj według customer_id