# mysql - Error Code: 1055(ONLY_FULL_GROUP_BY问题)
1.在mysql 5.7版本下报如下错误
Error Code: 1055. Expression #3 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
2.原因
是在5.7下mysql的model默认为ONLY_FULL_GROUP_BY
3.含义
sql中select后面的字段必须出现在group by后面,或者被聚合函数包裹,不然会抛出上面的错误 如以下sql
select A.column1, A.column2 from table as A group by column1 //会因为ONLY_FULL_GROUP_BY的缘故抛出上面错误
4.问题解决
去掉ONLY_FULL_GROUP_BY,重新设置值。
(前两种方式都是会话级别,建议修改文件)
select @@global.sql_mode
set @@global.sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
show VARIABLES like "sql_mode";
set sql