Endergebnis:
| customer_id | gap_days |
|-------------|----------|
| 1 | 123 |
| 2 | 120 |
mit cte als(
select order_id, customer_id, order_dt,
lag(order_dt) über(Partition by customer_id order by order_dt) als prev_order_ft,
datediff(Tag, prev_order_ft, order_dt) als gap_days
von Orders
)
wähle customer_id, max(gap_days) als gap_days
von cte
wo gap_days > 60
gruppe nach customer_id