报错内容如下:expression #2 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
原因:从5.7版本及以后的版本,默认设置了严格模式,你只能查询你执行分组字段的字段名!!!
这样操作就不会报错,如果你想解决这个问题,就按照下面的方法执行即可!!!
解决方法如下: 1.找到mysql安装根目录下的my.ini配置文件 2.根据你的mysql版本在该配置文件的mysqld配置下加入下面一条配置,如下图(我的版本是8.0,所以我以此为例):下面要区分mysql版本:5.7及更新的版本(8版本除外):sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTIONmysql8:sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
3.去重启mysql服务即可