Végső eredmény:
| customer_id | gap_days |
|-------------|----------|
| 1 | 123 |
| 2 | 120 |
with cte as(
select order_id, customer_id, order_dt,
lag(order_dt) over(partition by customer_id order by order_dt) as prev_order_ft,
datediff(day, prev_order_ft, order_dt) as gap_days
from Orders
)
select customer_id, max(gap_days) as gap_days
from cte
where gap_days > 60
group by customer_id