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

 

posted @ 2020-06-30 19:29  酸菜泡饭  阅读(308)  评论(0编辑  收藏  举报