报错:使用 group by 导致错误
[Err] 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'myphp.xiaofei.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
翻译:
[Err]1055-SELECT列表的表达式#1不在GROUP BY子句中,并且包含未聚合的列“myphp.xiaofei.id”,该列在功能上不依赖于GROUP BY子句中的列;这与sql\u mode=only\u full\u group\u by不兼容
解决:
1、查询 sql_mode
show variables like '%sql_mode%'
2、查看是否出现 ONLY_FULL_GROUP_BY
3、去掉 ONLY_FULL_GROUP_BY
set global sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
4、把当前会话的 sql_mode 也去掉
set session sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
5、到这里就解决了;如果还没有解决,请重启影响MySQL服务。