oracle sql - finding entries with dates (start/end column) overlap -
so data this:
id | start_date | end_date | uid | canceled ------------------------------------------------- 44 | 2015-10-20 22:30 | 2015-10-20 23:10 | 'one' | 52 | 2015-10-20 23:00 | 2015-10-20 23:30 | 'one' | 66 | 2015-10-21 13:00 | 2015-10-20 13:30 | 'two' |
there more 100k of these entries.
we can see start_date of second entry overlaps end_date of first entry. when dates overlap, entries lower id should marked true in 'canceled' column.
i tried queries take long time i'm not sure if work. want cover overlaping cases seems slow down.
i 1 responsible inserting/updating these entries using pl/sql
update table set column = 'value' id = '44'; if sql%rowcount = 0 insert values(...) end if
so maybe in step. tables updated/inserted using 1 big pl/sql created dynamically rows either updated or new ones inserted once again seems slow.
and of sql 'dialects' oracle 1 cryptic had chance work with. ideas?
edit: forgot 1 important detail, there 1 more column (uid) matched, update above
i start query:
update table t set cancelled = true exists (select 1 table t2 t.end_date > t2.start_date , t.uid = t2.uid , t.id < t2.id )
an index on table(uid, start_date, id)
might help.
as note: much easier when create table, because can use lag()
.
Comments
Post a Comment