loading
Please wait while loading...
返回 MySQL檢查時間或日期重疊
以下是4種會產生重疉的情況
(ns, ne, es, ee) = (new_start, new_end, existing_start, existing_end):
  1. ns - ne - es - ee: doesn't overlap and doesn't match (because ne < es)
  2. ns - es - ne - ee: ovarlaps and matches
  3. es - ns - ee - ne: ovarlaps and matches
  4. es - ee - ns - ne: doesn't overlap and doesn't match (because ns > ee)
  5. es - ns - ne - ee: ovarlaps and matches
  6. ns - es - ee - ne: ovarlaps and matches

SQL 語法 以下搜尋的版本

SQL Statment
Below method is found from internet while the second method is my own way usally use.
SELECT * FROM tbl WHERE
existing_start BETWEEN '$newStart' AND '$newEnd' OR
existing_end BETWEEN '$newStart' AND '$newEnd' OR
'$newStart' BETWEEN existing_star AND existing_end

以下是的個人慣常的做法, 兩者皆可找出重疊的紀錄

SELECT * FROM tbl WHERE
( existing_start<='$newStart' AND existing_end>'$newStart' )
AND ( existing_start<'$newEnd' AND existing_start>'$newStart' )
Comments
comments powered by Disqus