php 选择列表不在group by子句中,并且包含非聚集列laravel

vmjh9lq9  于 2022-12-17  发布在  PHP
关注(0)|答案(1)|浏览(101)
$all_ps = Palletstock::where('status', 0)
         ->where(function($query) use ($search) {
        $query->where('palletpart', 'like', '%'.$search.'%');
        $query->orwhere('location', 'like', '%'.$search.'%');
        $query->orWhere('supplier_code', 'like', '%'.$search.'%');
        $query->orWhere('qty', 'like', '%'.$search.'%');
        }) ->offset($start)->limit($length)->
        groupBy('palletpart','location','supplier_code', 'qty' )->get();

使用groupBy后,我得到了同样的错误“选择列表不在group by子句中,并且包含非聚合列”。

nukf8bse

nukf8bse1#

您有一个带分组的SQL查询,但您选择了所有列而没有分组聚合。这就像您有一个查询:

SELECT palletpart, location, supplier_code, qty, OTHER_COLUMN
FROM palletstock
GROUP BY palletpart, location, supplier_code, qty

那么最后一个OTHER_COLUMN必须是一些聚合函数,如SUM()、COUNT()、AVG(),即

SELECT palletpart, location, supplier_code, qty, SUM(OTHER_COLUMN)
FROM palletstock
GROUP BY palletpart, location, supplier_code, qty

相关问题