在 mysql 中,如何检查两个日期范围是否重叠?
我有以下代码:
注意:我们有
代码:
我有以下代码:
注意:我们有
p.date_started <= p.date_finished
,但dateA
可以等于dateB
或小于dateB
或大于dateB
。代码:
$query = "SELECT u.first_name, u.last_name, u.avatar_filename, p.id, p.user_id, p.address, p.topic, p.latitude, p.longitude, d.name AS department_name
FROM user u
JOIN placement p ON p.user_id=u.id
JOIN department d ON d.id = u.department_id
WHERE p.active=1 AND (('{$dateA}' BETWEEN p.date_started AND p.date_finished) OR
('{$dateB}' BETWEEN p.date_started AND p.date_finished) OR
(p.date_started BETWEEN '{$dateA}' AND '{$dateB}') OR
(p.date_finished BETWEEN '{$dateA}' AND '{$dateB}'))";
有没有更好的方法做这件事?
谢谢。