我試圖運行以下Query with Query builder。Connection.php中的Laravel QueryException第647行:SQLSTATE [42000]:語法錯誤或訪問衝突
$products = \DB::table('users')
->join('products','products.auth_id','users.id')
->leftjoin('buys','products.id','buys.product_id')
->select('products.*','users.avatar',DB::raw('COUNT(buys.product_id) as total_sells'))
->groupBy('products.id')
->where('products.status','=','1')
->take(20)
->paginate(4);
Where in products.id could be there in buys table or not..
但我得到以下錯誤。 我改變了database.php mysql array from strict = true to false
。
QueryException in Connection.php line 647:
SQLSTATE[42000]: Syntax error or access violation: 1055 'cart.products.name' isn't in GROUP BY
試着把你的'''groupBy''放在查詢的最後。 **編輯**:在'''where'之後''' – Treast
我試過了同樣的錯誤我得到的錯誤 – User57
噢,你的'''groupBy''需要指定你選擇的每一列(沒有聚合) 。所以基本上來自''''''''''和'''users.avatar'''的每一列。 – Treast