Laravel/Eloquent WHERE NOT子查询

4

我遇到了设置负条件的问题,例如:

WHERE NOT( "last_day" "<=" $first_day OR "first_day" "<=" $last_day)

我的查询构建器目前如下:

$query = $query->where(function ($query) use ($first_day, $last_day) {
   $query->where('last_day', '<=', $first_day);
   $query->orWhere('first_day', '<=', $last_day);
});

我愿意将其设置为这样:
$query = $query->whereNot(function ($query) use ($first_day, $last_day) {
  $query->where('last_day', '<=', $first_day);
  $query->orWhere('first_day', '<=', $last_day);
});

总结一下:我想在一个否定的WHERE条件中使用OR语句。我该如何实现?
来源:http://baodad.blogspot.nl/2014/06/date-range-overlap.html

我认为你的操作数不正确。你具体是在检查什么? - aynber
它们确实不是,我会进行编辑并完全指定。 - MrMedicine
我想做的基本上是:https://dev59.com/ibeqzYgBFxS5KdRjEv-K - MrMedicine
2个回答

0

你可以玩弄逻辑

$query = $query->where(function ($query) use ($first_day, $last_day) {
   $query->where('last_day', '>', $first_day);
   $query->where('first_day', '>', $last_day);
});

我认为逻辑不同,因此不符合“艾伦区间代数”的条件:https://en.wikipedia.org/wiki/Allen%27s_interval_algebra - MrMedicine
将:$query->where('first_day', '>', $last_day); 改为 $query->where('first_day', '<', $last_day); 并且它是正确的,请参见:http://stackoverflow.com/questions/43233652/eloquent-mysql-statement-where-nota-or-b - MrMedicine

0

根据此处找到的答案,按照还原约束条件的方式进行操作:Eloquent MYSQL语句:WHERE NOT(A OR B)

$query = $query->where('last_day', '>', $first_day)->where('first_day', '>', $last_day);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接