mysql报错如下:
SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of
SELECT list is not in GROUP BY clause and contains nonaggregated column
which is not functionally dependent on columns in GROUP BY clause;
this is incompatible with sql_mode=only_full_group_by
是由于mysql默认开启严格模式,当select字段比group by使用到的字段多的时候,会报错。
可以减少多余的select的字段,或者关闭严格模式(mysql中设置 或 laravel中设置)
我选择的解决方法是在laravel的 config/database.php 中设置 strict 为false,关闭严格模式。
当然关闭严格模式会有一些其他的影响,比如varchar字符长度超过了指定的长度,会截取到指定长度,而不会报错等。
不过不会有大的影响,可以放心使用。
原文地址:
https://wyq2214368.github.io/2019/07/30/php/laravel-de-groupby-bao-cuo-wen-ti-chu-li/