SQL查找日期时间超出日期时间范围

SQL查找日期时间超出日期时间范围,sql,Sql,我有两张表,一张叫做生产,另一张叫做时间表。 我想知道是否有一些生产超出了计划。 到目前为止,我得到了重复的价值,因为生产可能在一个计划内,但在另一个计划外。 到目前为止,我对这个sql查询没有任何运气,我想知道是否有人能为我指出正确的方向 提前谢谢 SELECT TB1.* FROM Production AS TB1 INNER JOIN Schedule AS TB2 ON TB1.ProduceDate < TB2.StartDate OR TB1.ProduceDate >

我有两张表,一张叫做生产,另一张叫做时间表。 我想知道是否有一些生产超出了计划。 到目前为止,我得到了重复的价值,因为生产可能在一个计划内,但在另一个计划外。 到目前为止,我对这个sql查询没有任何运气,我想知道是否有人能为我指出正确的方向

提前谢谢

SELECT TB1.*
FROM Production AS TB1
INNER JOIN Schedule AS TB2
ON TB1.ProduceDate < TB2.StartDate OR TB1.ProduceDate > tb2.EndDate
GROUP BY TB1.ID,TB1.ProduceDate
ORDER BY Tb1.ProduceDate

ID  Produce Date
1   2017-02-03 09:00:00.000
2   2017-02-03 11:00:00.000
3   2017-02-03 13:00:00.000
4   2017-02-03 18:00:00.000
7   2017-02-03 19:00:00.000
5   2017-02-03 20:00:00.000
6   2017-02-03 23:00:00.000
明细表数据

ID  ProduceDate
1   2017-02-03 09:00:00.000
2   2017-02-03 11:00:00.000
3   2017-02-03 13:00:00.000
4   2017-02-03 18:00:00.000
5   2017-02-03 20:00:00.000
6   2017-02-03 23:00:00.000
7   2017-02-03 19:00:00.000
ID  StartDate               EndDate
1   2017-02-03 10:00:00.000 2017-02-03 12:00:00.000
2   2017-02-03 15:00:00.000 2017-02-03 19:00:00.000
我想你只是想不存在:

我想你只是想不存在:


我删除了不兼容的数据库标记。请仅使用您真正使用的数据库进行标记。我删除了不兼容的数据库标记。请仅使用您真正使用的数据库进行标记。
select p.*
from production p
where not exists (select 1
                  from schedule s
                  where p.producedate >= s.startdate and
                        p.producedate <= s.enddate
                 );
select Production.*
from Production
left join Schedule
  on ProduceDate between StartDate and EndDate

where Schedule.id is null