我正在开发日期范围重叠功能,可以用 13 个正条件编写该功能来检查日期间隔是否重叠:
https://en.wikipedia.org/wiki/Allen%27s_interval_algebra https://en.wikipedia.org/wiki/Allen%27s_interval_algebra
或者更优雅地在两个负面条件下:
http://baodad.blogspot.nl/2014/06/date-range-overlap.html http://baodad.blogspot.nl/2014/06/date-range-overlap.html
在 MYSQL 中:
WHERE NOT(`last_day` <= '2001-06-01' OR `first_day` >= '2022-12-01');
这需要这样的东西,我在文档中找不到:
$query = $query->whereNot(function ($query) use ($first_day, $last_day) {
$query->where('last_day', '<=', $first_day);
$query->orWhere('first_day', '<=', $last_day);
});
我该如何解决这个问题?
这与我的其他可能重复的帖子有关:Laravel / Eloquent WHERE NOT SUBQUERY https://stackoverflow.com/questions/43215081/laravel-eloquent-where-not-subquery
但我希望我的问题现在更清楚了。
您可以通过恢复对的限制来实现您所需要的last_day and 第一天- 这样就不需要使用NOT clause.
而不是做
WHERE NOT(`last_day` <= '2001-06-01' OR `first_day` >= '2022-12-01');
你可以做
WHERE `last_day` > '2001-06-01' AND `first_day` < '2022-12-01';
使用 Eloquent 构建器,以下内容应该可以解决问题:
$query = $query->where('last_day', '>', $first_day)->where('first_day', '>', $last_day);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)