Find conflicted date intervals using SQL

前端 未结 5 1284
梦谈多话
梦谈多话 2021-01-05 18:28

Suppose I have following table in Sql Server 2008:

ItemId StartDate   EndDate
1      NULL        2011-01-15
2      2011-01-16  2011-01-25
3      2011-01-26           


        
5条回答
  •  悲&欢浪女
    2021-01-05 18:52

    Something like this should give you all overlaping periods

    SELECT
    * 
    FROM
    mytable t1 
    JOIN mytable t2 ON t1.EndDate>t2.StartDate AND t1.StartDate < t2.StartDate 
    

    Edited for Adrians comment bellow

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题