我有两个表,每个表都有两个日期字段 - fromdate 和 todate。使用 SQL Server,我需要从 table1 中找到所有行,它们的起始日期范围不与 table2 中的日期范围重叠。我目前正在使用以下
Select fromdate,todate
from table1
Where not exists
(select fromdate,todate
from table2
where table1.todate > table2.fromdate
and table1.fromdate < table2.todate)
但是这很慢(这只是一个简化的例子)。有没有更好的方法,例如使用连接或 CTE?