gpt4 book ai didi

php - 尝试在 where 子句中将字段与 0 进行比较时的奇怪行为

转载 作者:搜寻专家 更新时间:2023-10-31 22:01:54 25 4
gpt4 key购买 nike

假设我的数据库中有 2 条记录:

--  Name  -- approved -- resolved
-- Record1 -- 1 -- 0
-- Record2 -- 1 -- 1

我正在使用 Where 子句获取记录

$results = DB::table('mytable')->where('mytable.approved','=',1)->where('mytable.resolved','=',0);

奇怪的行为是如果 resolved=0 ,它拒绝获取 Record1 行,

如果我将查询更改为

$results = DB::table('mytable')->where('mytable.approved','=',1)->where('mytable.resolved','>',0); 

它确实获取 Record2

谁知道哪里出了问题?

我尝试使用字段类型并将其设为 boolean 和 null ,但没有帮助。

最佳答案

嘿,使用 whereRaw 可能是下面的代码为你工作

$results = DB::table('mytable')->whereRaw("mytable.approved = 1 AND mytable.resolved = 0");

试试这个

它解决了你的问题。

关于php - 尝试在 where 子句中将字段与 0 进行比较时的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27545351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com