laravel 的group by报错

出错提示: Syntax error or access violation: 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'kuaigangnewsql.goods.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sqlmode=onlyfullgroupby
释义: 语法错误或访问冲突:选择列表的1055表达式#2不在GROUP BY子句中,包含非聚合列“kuaigangnewsql.goods”。在功能上不依赖于GROUP BY子句中的列的id';这与sqlmode=onlyfullgroupby不兼容

解决方案:

这个原因是因为 laravel配置中的strict配置问题, 因为在配置中配置为true的时候,laravel的groupBy会为所有的例分组, 设置为false之后,他只会为你指定的列分组,就可以解决这个问题。

修改config -database.php 中 'strict' => true

引用:

1:https://blog.csdn.net/lishenyangd/article/details/80969531
2:https://blog.csdn.net/linyunping/article/details/78497947

张闯

继续阅读此作者的更多文章