原文链接:https://blog.csdn.net/loveliness_peri/article/details/88051316
是由于默认的 MySQL 配置中 sql_mode 配置了 only_full_group,需要 GROUP BY
中包含所有 在 SELECT 中出现的字段。
only_full_group_by说明:
only_full_group_by :使用这个就是使用和oracle一样的group 规则,
select的列都要在group中,或者本身是聚合列(SUM,AVG,MAX,MIN) 才行,
其实这个配置目前个人感觉和distinct差不多的,所以去掉就好
SELECT * FROM 表名称 GROUP BY 字段
1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains
nonaggregated column 'XXX' which is not functionally dependent on columns
in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
出现问题原因:sql_mode里面多了:ONLY_FULL_GROUP_BY
使用 SQL 语句可以查询这个配置:
select @@sql_mode;
解决方法:在配置文件添加对应设置:(就是执行上面的查询sql_mode语句;去掉ONLY_FULL_GROUP_BY即可)
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION