且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在开始日期和结束日期之间选择值

更新时间:2023-01-29 20:12:56

我读这个问题是为了寻找范围的重叠:

I read this problem as looking for the overlap of ranges:

所以你有数据范围:T1到T3。并寻找与范围T2到T4的重叠。因为它们重叠,你想要。
但是,如果数据是T1到T3,范围是T4到T5 ..没有重叠,因此不想要。

so you have data in range: T1 to T3. And looking for overlap with range T2 to T4. Since they overlap, you want. However, if data is T1 to T3 and range is T4 to T5 .. no overlap so don't want.

您可以使用此查询:

Select id 
  from eventos_sapo 
 where startDate <= '2015-02-14'
   AND endDate >= '2013-01-03';

因此,如果它在给定日期(2015年2月14日)之后开始,则不包括。
或如果它在2013年1月3日之前结束...不包括它。
包含其他所有内容,因为它重叠:

So if it started after the given date (Feb 14, 2015), then don't include it. or if it ended prior to Jan 3, 2013 ... don't include it. Include everything else, since it overlaps:

例如:
数据在给定范围开始日期之后结束,数据开始日期因此它是以下情况之一:

As 1 example: Data ends after the given range start date, and the data start date is prior to end, so it's one of the following cases:

Data:           |---|
Given range:      |---|

Data:           |-------|
Given range:      |---|

Data:             |---|
Given range:    |---|

Data:             |---|
Given range:    |-------|