TP5框架如何用Db类查询这条sql语句

select*fromgoodswhere(id=1andprice=1)and(status=0orstatus=2)... select * from goods where (id=1 and price=1) and (status=0 or status=2) 展开
 我来答
miniappcy3tv95eaedrf
2019-04-08 · TA获得超过2363个赞
知道大有可为答主
回答量:1909
采纳率:92%
帮助的人:1087万
展开全部

你这段sql,前面那个括号是没必要的,全部是and

Db::name('goods')->where('id',1)->where('price',1)
->whereIn('status',[0,2]);

这个写法可以达到你要的效果

也可以通过where嵌套,生成出来 就是你写的那种

Db::name('goods')->where('id',1)->where('price',1)
->where(function($db){
    return $db->where('status',1)->whereOr('status',2);
});

希望对你有帮

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式