In aggregated query without GROUP BY, expression #3 of SELECT list contains nonaggregated column 'emsdb_pro.mainspareparts.CreationTime'; this is incompatible with sql_mode=only_full_group_by

错误:

In aggregated query without GROUP BY, expression #3 of SELECT list contains nonaggregated column 'emsdb_pro.mainspareparts.CreationTime'; this is incompatible with sql_mode=only_full_group_by

原因是:当mysql的sql_mode存在only_full_group_by的时候,在不使用group by 并且select后面出现聚集函数的话,那么所有被select的都应该是聚集函数,否则就会报错。

解决:

在mysql 的配置文件(my.ini)中修改

注意:要将sql_mode配置放置在[mysqld]节下面

In aggregated query without GROUP BY, expression #3 of SELECT list contains nonaggregated column 'emsdb_pro.mainspareparts.CreationTime'; this is incompatible with sql_mode=only_full_group_by

 保存文件后使用命令行重启数据库:

net stop mysql

net start mysql

In aggregated query without GROUP BY, expression #3 of SELECT list contains nonaggregated column 'emsdb_pro.mainspareparts.CreationTime'; this is incompatible with sql_mode=only_full_group_by

执行之后到数据库中执行

set @@global.sql_mode = `STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION`;

在使用select @@global.sql_mode查询

结果中就不存在

ONLY_FULL_GROUP_BY

In aggregated query without GROUP BY, expression #3 of SELECT list contains nonaggregated column 'emsdb_pro.mainspareparts.CreationTime'; this is incompatible with sql_mode=only_full_group_by