解决MySQL5.7版本之后使用GROUP BY语句时报错
今天使用mysql简单的一句分组查询语句(GROUP BY)报错了。
mysql> SELECT * FROM tb GROUP BY empid;
ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'db1.tb.sales' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
查了问题原因和解决方法,成功解决。
问题原因
原因:使用GROUP BY 语句违背了sql_mode=only_full_group_by。因为mysql版本5.7之后默认的模式是ONLY_FULL_GROUP_BY。官网文档的原话:
说人话ÿ