如何从查询Laravel获得相反的结果 [英] how to get opposite results from a query Laravel
问题描述
如何从 SELECT 查询中获得相反的结果
How to get the opposite results from a SELECT query
下面是我的查询
$fod = FodMap::select('*')
->where('fructose_level', $fructose == 1 ? '=' : '>=', $fructose)
->where('lactose_level', $lactose == 1 ? '=' : '>=', $lactose)
->where('polyols_level', $polyols == 1 ? '=' : '>=', $polyols)
->where('fructan_level', $fructan == 1 ? '=' : '>=', $fructan)
->get();
我想获取不属于上述查询范围的所有内容.请咨询
I want to get everything that doesn't fall under the above query. pls advice
推荐答案
好吧,我想了一段时间,我认为解决方案并不像您首先提出的那样复杂(当我先阅读时,我以为您想要反转结果.
Ok, I thought about your question for some time and I think the solution is not as complicated as you asked first (when I've read it first, I thought you want inverted result).
- 在您的评论之一中,您写道:
以上结果给出了用户无法食用的食物列表. 希望它得到上面不匹配的结果
above results gives the list of foods which user can't eat.. what i want it to get the results which not matching above
- 我已经读过果糖含量等信息.总的来说,高于1的果糖是不好的,低于1的果糖是好的.
那么,解决方案太简单了:
So, solution is way too simple then:
$fod = FodMap::select('*')
->where('fructose_level', '<', $fructose)
->where('lactose_level', '<', $lactose)
->where('polyols_level', '<', $polyols)
->where('fructan_level', '<', $fructan)
->get();
另外,原始查询中的三元运算符也没有意义,因为子句如下:
Also, ternary operators in your original query do not make sense, because clause like:
->where('fructose_level', $fructose == 1 ? '=' : '>=', $fructose)
将始终用作:
->where('fructose_level', '>=', $fructose)
考虑一下.
这篇关于如何从查询Laravel获得相反的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!