1055 (42000): Expression #7 of SELECT list is not in GROUP BY clause and contains nonaggregated

mysql中报的异常信息

ERROR 1055 (42000): Expression #7 of SELECT list is not in GROUP BY clause and contains 
nonaggregated column 'xxxxx' which is not functionally dependent on 
columns in GROUP BY clause; this is incompatible withsql_mode=only_full_group_by

同样的sql换了高版本的数据库(8.0.23)就报了这个错,这是因为5.7以上的版本中,在使用 group by 时,如果select后边查询的列,没有包含在group by中,那么这个SQL会被认为是非法操作。

处理过程:
先查询

SELECT @@sql_mode;

返回结果:
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION*
去掉标黄的"only_full_group_by",复制下来
然后执行

SET sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

再修改一下全局的:
这个对于以后新建的数据库都起作用

SET @@global.sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

然后再执行sql就没问题了,要是不嫌麻烦的话,就去把sql修改一下,修改成和异常提示要求一致的格式

你可能感兴趣的:(数据库,数据库,sql,mysql,1055)