我需要以 Laravel 格式转换此查询,我尝试使用 'WhereNotIn' ,但我没有得到我想要的结果。有人可以帮助我吗?
SELECT
em.erp_mlbid AS category_id
FROM
erp_product AS ep
INNER JOIN
erp_product_description AS epd ON epd.erp_productid = ep.erp_productid
INNER JOIN
erp_product_category AS epc ON epc.erp_productid = ep.erp_productid
INNER JOIN
erp_mlbcategory_erpcategory AS emc ON emc.erp_categoryid = epc.erp_categoryid
INNER JOIN
erp_mlb_category AS em ON em.erp_mcid = emc.erp_mlbcategoryid
INNER JOIN
erp_product_image AS epi ON epi.erp_productid = ep.erp_productid
WHERE
ep.erp_productid NOT IN (
SELECT
epm.erp_productid
FROM
erp_product_to_mlb AS epm
)
AND ep.erp_quantity > 0
AND ep.erp_status > 0
LIMIT
1
显然,我的“WhereNotIn”行被忽略了,结果是一样的:
$categoria = DB::table('erp_product')
->join('erp_product_category','erp_product_category.erp_productid', '=', 'erp_product.erp_productid')
->join('erp_mlbcategory_erpcategory', 'erp_mlbcategory_erpcategory.erp_categoryid', '=','erp_product_category.erp_categoryid')
->join('erp_mlb_category', 'erp_mlb_category.erp_mcid', '=', 'erp_mlbcategory_erpcategory.erp_mlbcategoryid')
->select('erp_mlb_category.erp_mlbid')
->whereNotIn('erp_product.erp_productid', function($q){
$q->select('erp_productid')->from('erp_product_to_mlb');
})
->get();
你有一个错字:
->whereNotIn('erp_product.erp_producid'
应该:
->whereNotIn('erp_product.erp_productid'
请注意拼写错误的productid
.
您可以做的一件事是删除->get()
调用,使其$categoria
成为查询对象,然后执行此操作,以便您可以看到组装的查询:
dd($categoria->toSql());
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句