报错
Expression #1 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
原因
MySQL错误-this is incompatible with sql_mode=only_full_group_by完美解决方案_格子衫111的博客-CSDN博客有时候,遇到数据库重复数据,需要将数据进行分组,并取出其中一条来展示,这时就需要用到group by语句。但是,如果mysql是高版本,当执行group by时,select的字段不属于group by的字段的话,sql语句就会报错。报错信息如下:> Expression #1 of SELECT list is not in GROUP BY clause and contains> nonaggregated column '数据库名.表名.字段名' which is not functiona_this is incompatible with sql_mode=only_full_group_byhttps://blog.csdn.net/u012660464/article/details/113977173
解决办法
长期解决方案 - 修改mysql配置文件
windows+PHPStudy+MySQL5.7修改
D:\phpstudy_pro\Extensions\MySQL5.7.26\my.ini
找到组[mysqld] (不是[mysql])
在组最后加一行
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
保存,重启电脑,即可