我有一个包含以下列的表格:
sID、start_date和end_date。
其中一些值如下:
1 1995-07-28 2003-07-20
1 2003-07-21 2010-05-04
1 2010-05-03 2010-05-03
2 1960-01-01 2011-03-01
2 2011-03-02 2012-03-13
2 2012-03-12 2012-10-21
2 2012-10-22 2012-11-08
3 2003-07-23 2010-05-02
我只想要第二行和第三行,因为它们是重叠的日期范围。
我尝试了这个方法,但它无法去掉第一行。不确定我哪里出错了?
select a.sID from table a
inner join table b
on a.sID = b.sID
and ((b.start_date between a.start_date and a.end_date)
and (b.end_date between a.start_date and b.end_date ))
order by end_date desc
我正在尝试在SQL Server中完成以下操作。