this is incompatible with sql_mode=only_full_group_by

报错信息:

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'xxxx' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

原因:

这是因为mysql5.7及以上版本的mysql中,对于 group by 的这种聚合操作,如果在select 中的列,
没有在group by 中出现,那么这个SQL是不合法的,因为列不在group by的从句中,所以对于设置了这个mode的数据库,在使用group by 的时候,就要用MAX(),SUM(),ANT_VALUE()的这种聚合函数,才能完成GROUP BY 的聚合操作。

解决方法:

1、首先查询你的数据库是否包含:only_full_group_by

select @@global.sql_mode

2、如果包含接着下面的步骤,修改my.cnf

vim my.cnf

找到sql_mode 去掉only_full_group_by

this is incompatible with sql_mode=only_full_group_by_第1张图片

如果没有sql_mode 追加如下代码:

sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

3、重启mysql

systemctl restart mysqld

你可能感兴趣的:(MySQL问题,sql,数据库,mysql)