0
我使用的是Laravel 5.5,我想顯示由最頻繁銷售的物品訂購的產品清單,因此我對shipping_detail表進行了關聯,但是我得到了錯誤。下面的代碼:Laravel 5.5根據關係計數顯示產品訂單清單
Produk::select('product.*', \DB::raw('COUNT(shipping_detail.product_code) as total'))
->leftJoin('shipping_detail', 'shipping_detail.product_code', '=', 'product.product_code')
->whereIn('product.category_id', $cat)
->orWhere('product.category_id', $prod_cat_id)
->groupBy('product.product_code')
->orderBy('total', 'desc')
->limit(7)
->get();
錯誤:
SQLSTATE[42000]: Syntax error or access violation: 1055 'store.product.category_id' isn't in GROUP BY
我必須把產品表中的所有列在GROUP BY或有另一種方式來做到這一點更簡單?
https://stackoverflow.com/questions/41571271/group-by-not-working-laravel –
解決了..謝謝@AndriyLozynskiy –