解决1055 - Expression #1......this is incompatible with sql_mode=only_full_group_by

Posted 酸菜泡饭

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决1055 - Expression #1......this is incompatible with sql_mode=only_full_group_by相关的知识,希望对你有一定的参考价值。

mysql-8.0.20版本

问题:

1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column \'usertest.users.id\' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by, Time: 0.000000s

 

解决办法:

打开终端,进入mysql。

mysql> SHOW SESSION VARIABLES;
mysql> SHOW GLOBAL VARIABLES;
mysql> select @@sql_mode;

通过上面的命令可以查看sql_mode

only_full_group_by :使用这个就是使用和oracle一样的group 规则, select的列都要在group中,或者本身是聚合列(SUM,AVG,MAX,MIN) 才行,其实这个配置目前个人感觉和distinct差不多的,所以去掉就好。

mysql> set global sql_mode=\'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\';
mysql> set session sql_mode=\'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\';

将sql_mode修改为去掉only_full_group_by之后的数据。再次运行sql语句就OK了。

 

以上是关于解决1055 - Expression #1......this is incompatible with sql_mode=only_full_group_by的主要内容,如果未能解决你的问题,请参考以下文章

MySQL-[Err] 1055 - Expression #1

#1055 - Expression of SELECT list is not in GROUP BY clause and contains nonaggregated column this i

[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause 的问题 MySQL

[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause 的问题 MySQL

1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contai

MySQL_group by报错 [ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause]