本文转自CSDN 链接地址:http://blog.csdn.net/dasihg/article/details/8450195
时间段:starttime_1到endtime_1,starttime_2到endtime_2 SQL语句:where least(endtime_1, endtime_2) > greatest(starttime_1, starttime_2) 解释:least取最小值,greatest取最大值。 创建函数least、greatest CREATE FUNCTION least ( @time1 datetime, @time2 datetime ) RETURNS datetime AS BEGIN declare @ret datetime if(@time2>@time1)set @[email protected] else set @[email protected] return @ret END GO CREATE FUNCTION greatest ( @time1 datetime, @time2 datetime ) RETURNS datetime AS BEGIN declare @ret datetime if(@time2<@time1)set @[email protected] else set @[email protected] return @ret END GO
时间: 2024-11-20 03:08:49