在使用mysql中group by 关键字做分组操作的时候出现如下错误
ERROR 1055 (42000): Expression #3 of SELECT list is not in GROUP BY clause and
contains nonaggregated column 'person.teacher.t_name' which is not functionally
dependent on columns in GROUP BY clause; this is incompatible with
sql_mode=only_full_group_by
翻译如下
错误1055(42000):选择列表的表达式3不在group by子句中,并且包含非聚合列“person.teacher.t_name”,它在功能上不依赖group by子句中的列;这与sql_mode=only_full_group_by不兼容
其实这句话的意思是 mysql 规定在你写的查询表达式中,group by 后面跟的分组条件在你查找的内容里必须存在才行,如果你查询了条件不符合就报错,不兼容,简单来说就是模式不正确
解决方案如下
设置 sql_mode;
mysql>SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
运行后即可