Sobes.tech
Middle

Konečný výsledek: | customer_id | gap_days | |-------------|----------| | 1 | 123 | | 2 | 120 | s cte jako( vyberte order_id, customer_id, order_dt, lag(order_dt) přes(částice podle customer_id řadit podle order_dt) jako prev_order_ft, datediff(dne, prev_order_ft, order_dt) jako gap_days z Orders ) vyberte customer_id, max(gap_days) jako gap_days z cte kde gap_days > 60 group by customer_id