Detect overlapping date ranges from the same table

前端 未结 9 1163
甜味超标
甜味超标 2020-12-01 04:26

I have a table with the following data

PKey  Start       End         Type
====  =====       ===         ====
01    01/01/2010  14/01/2010  S
02    15/01/2010         


        
9条回答
  •  难免孤独
    2020-12-01 04:42

    BTW - If you don't have a unique id , against your dates you can do this is oracle..FYI

    with date_ranges
    as
    (
    SELECT 
         rownum as pkey,
        date_ranges.*
    FROM  date_ranges
    ) 
    select 
    dr1.* 
    from 
    date_ranges dr1 , date_ranges dr2
    where  dr1.pkey > dr2.pkey
    AND dr1.end_dt >= dr2.start_dt 
    AND dr2.end_dt >= dr1.start_dt
    

提交回复
热议问题