【发布时间】:2014-10-03 08:36:31
【问题描述】:
好的,所以这个特殊的用例让我有点头疼。
我要做的是确定一个集合中的任何 StartDate 和 EndDates 是否与一组 StartDate 和 EndDates 重叠,如果是,则必须返回重叠的行。
DateRange 表 -- 包含所有 DateRanges
DateRangeId StartDate EndDate CustomerJobQuery_Id WorkWish_Id
----------- --------------------------- --------------------------- ------------------- -----------
1 2014-03-31 00:00:00.0000000 2014-08-18 00:00:00.0000000 NULL 1
2 2014-08-25 00:00:00.0000000 2014-09-15 00:00:00.0000000 NULL 1
3 2013-08-24 00:00:00.0000000 2014-09-25 00:00:00.0000000 1 NULL
工作愿望表
Id Candidate_Id
----------- ------------
1 5
CustomerJobQuery 表
Id Customer_CustomerId
----------- -------------------
1 2
这是我的 DateRange 表。我的 StoredProcedure 接受的是 CandidateId;我希望找到候选人 ID 的 WorkWishes ,将 WorkWish 的 DateRanges 与所有 CustomerJobQuery DateRanges 匹配并返回具有重叠日期的 CustomerJobQueries。
我想出了如何检查一个特定的 DateRange 是否与另一个 DateRange 重叠。但我不知道如何在一个集合上进行这种比较。
非常感谢任何帮助!
【问题讨论】:
标签: sql sql-server database tsql datetime