Galutinis rezultatas:
| customer_id | gap_days |
|-------------|----------|
| 1 | 123 |
| 2 | 120 |
su cte kaip(
pasirinkite order_id, customer_id, order_dt,
lag(order_dt) per(partition by customer_id order by order_dt) kaip prev_order_ft,
datediff(day, prev_order_ft, order_dt) kaip gap_days
iš Orders
)
pasirinkite customer_id, max(gap_days) kaip gap_days
iš cte
kur gap_days > 60
grupuoti pagal customer_id