欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MySQL判斷時(shí)間段是否重合的兩種方法

 更新時(shí)間:2022年07月08日 09:56:55   作者:小旭2021  
這篇文章介紹了MySQL判斷時(shí)間段是否重合的兩種方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

兩種寫法。如圖,4種重合情況和2種不重合情況。

第一種寫法:

-- 時(shí)間段 a,b  
SELECT * FROM table WHERE
       (start_time >= a and end_time <= b) -- 被包含了
    or (end_time >= a and end_time <=b)
    or (start_time >= a and start_time <=b)
    or (start_time <= a and end_time >=b)

解析:where后的4個(gè)條件分別代表了圖中4種重合的情況。
但是第一種情況被2和3包含了,所以簡(jiǎn)化一下寫法:

SELECT * FROM table WHERE
    (end_time >= a and end_time <=b)
    or (start_time >= a and start_time <=b)
    or (start_time <= a and end_time >=b);

第二種寫法:

SELECT * FROM table WHERE not (start_time > b or end_time < a);

到此這篇關(guān)于MySQL判斷時(shí)間段是否重合的文章就介紹到這了。希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論