![](/img/trans.png)
[英]Failed to Run Query: Exception in Connection.php line 673: SQLSTATE[42000]: Syntax error or access violation: 1064
[英]Laravel QueryException in Connection.php line 647: SQLSTATE[42000]: Syntax error or access violation
我试图运行以下带有查询的查询构建器。
$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
尝试
$products = \DB::table('users')
->selectRaw('products.*,users.avatar, COUNT(buys.product_id) as total_sells')
->where('products.status','=','1')
->join('products','products.auth_id','=', 'users.id')
->leftjoin('buys','products.id','buys.product_id')
->groupBy('products.id')
->take(20)
->get();
我不确定分页功能是否会查询生成器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.