且构网

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

在SQL Server中选择具有多个行条件的记录

更新时间:2023-02-07 14:02:20

此联接将起作用:

select * 
from t1
join t2 on t1.day = t2.day and t1.end >= t2.start and t1.start <= t2.end

如果时间列为varchars,则需要转换为time:

If time columns are varchars you need to cast to time:

select * 
from t1
join t2 on t1.day = t2.day and 
           cast(t1.end as time) >= cast(t2.start as time) and 
           cast(t1.start as time) <= cast(t2.end as time)