解决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

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

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-锁机制


下一篇:oracle 03-16 数据库维护