आप lag()
. का उपयोग कर सकते हैं और फिर फ़िल्टर करें:
select t.*,
datediff(start, prev_cancelled) as num_days_since_cancel
from (select t.*,
lag(cancelled) over (partition by id order by start) as prev_cancelled
from t
) t
where prev_cancelled is not null;
यहां एक डीबी<>बेला है।