zoukankan      html  css  js  c++  java
  • sql 判断两个时间段是否有交集

    本文转自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 @ret=@time1
     else set @ret=@time2
    return @ret
    END
    GO
    
     
    
    CREATE FUNCTION greatest
    (
     @time1 datetime,
     @time2 datetime
    )
    RETURNS datetime
    AS
    BEGIN
    declare @ret datetime
     if(@time2<@time1)set @ret=@time1
     else set @ret=@time2
    return @ret
    END
    GO
    

      

  • 相关阅读:
    九九乘法表
    计算器界面
    3.2封装的日期类
    杨辉三角
    100以内的素数
    九九 乘法表
    七、logging模块
    六、MySQLdb 模块
    四、浏览器运行模式
    五、configparser模块
  • 原文地址:https://www.cnblogs.com/alphafly/p/3967987.html
Copyright © 2011-2022 走看看