MySQL错误Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated colum

程序提示错误:Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column

原因:数据库sql_mode设置有问题

解决方法:
1、打开mysql,查看sql_mode的值:select version(), @@sql_mode;
2、可以看到查询到的结果中含有 ‘ONLY_FULL_GROUP_BY’ 这个值;
3、修改MySQL配置文件:my.ini或my.cnf
在文件中新增如下语句:sql_mode=‘STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION’
4、重新启动MySQL服务器即可MySQL错误Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated colum_第1张图片

你可能感兴趣的:(MySQL错误Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated colum)