MYSQL查询报错 Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column

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

原因:在MySQL5.7.5后,默认开启了ONLY_FULL_GROUP_BY,所以导致了之前的一些SQL无法正常执行,其实,是我们的SQL不规范造成的,因为group by 之后,返回的一些数据是不确定的,所以才会出现这个错误。

解决办法:

修改下sql_mode即可:

查看:select version(), @@sql_mode;
修改:SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

建议:
select version(), @@sql_mode;
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

select version(), @@global.sql_mode
set @@global.sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'

你可能感兴趣的:(MYSQL查询报错 Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column)