繁体   English   中英

Connection.php第647行中的Laravel QueryException:SQLSTATE [42000]:语法错误或访问冲突

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM