
最佳答案





讨论数量:
DB::table('dp_goods')->where('status',1)->whereColumn('brand_id','dp_goods_brand.id')->selectRaw('count(*)')
where 的常用参数签名是 字段
, 操作符
, 值
,操作符省略时为 =
,你这里的参数就有问题呐。
其次,按照你的描述,应当使用关联表+子查询的方式来做才对。
换句话说,你应该先把 SQL 出来,再转成查询构建器的方式,至于怎么转换,你可以让 ChatGPT 帮你弄,也可以找一些在线的转换工具。
DB::table("dp_goods_brand")->where('status',1)->whereRaw("3 > (select count(*) from dp_goods where dp_goods.brand_id = dp_goods_brand.id and dp_goods.status = 1)")->get();