You can use lag()
to get a time period before each event. Then join
:
select e.*, r.*
from rankings r left join
(select e.*,
lag(event_date) over (order by event_date) as prev_event_date
from events e
) e
on r.ranking_date < event_date and
(r.ranking_date >= prev_event_date or prev_event_date is null)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…