Detect overlapping date ranges from the same table

前端 未结 9 1156
甜味超标
甜味超标 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:59

    select A.*
    from MyTable A
    inner join MyTable B
    on (B.start <= A.end)
    and (B.end >= A.start)
    

    or something like that (assuming dates are not nullable and equal dates count as an overlap).

提交回复
热议问题