mysql查询出现In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated c
出现问题:
Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: In aggregated query without GROUP BY,expression #2 of SELECT list contains nonaggregated column 'pay.t.type'; this is incompatible with sql_mode=only_full_group_by
出现原因:
在MySQL5.7.5后,默认开启了ONLY_FULL_GROUP_BY,所以导致了之前的一些SQL无法正常执行,其实,是我们的SQL不规范造成的,因为group by 之后,返回的一些数据是不确定的,所以才会出现这个错误。
解决方案,两种:
方案一:修改SQL,因为出现这个问题,基本都是因为这个问题造成的,不确定返回字段可以使用ANY_VALUE(column_name)。
方案二:关闭ONLY_FULL_GROUP_BY,我的是Linux环境,我就说一下Linux的解决步骤:
①、登录进入MySQL,linux登录的:mysql -u username -p ,然后输入密码,输入SQL:show variables like '%sql_mode';
②、编辑my.cnf文件,文件地址一般在:/etc/my.cnf,/etc/mysql/my.cnf,找到sql-mode的位置,去掉ONLY_FULL_GROUP_BY,然后重启MySQL;有的my.cnf中没有sql-mode,需要加入:
sql-mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,注意要加入到[mysqld]下面,我就是加入到其他地方,重启后也不生效,具体的如下图:
③、修改成功后重启MySQL服务,service mysql restart,重启好后,再登录mysql,输入SQL:show variables like '%sql_mode'; 如果没有ONLY_FULL_GROUP_BY,就说明已经成功了。
- mysql5.7执行sql语句报错:In aggregated query without GROUP BY, expression #1 of SELECT list contains nonagg
- mysql5.7执行sql语句报错:In aggregated query without GROUP BY, expression #1 of SELECT list contains nonagg
- 解决MySql查询语句报Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre异常的问题
- mysql遇见Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre的问题
- Docker安装MySQL遇见Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre的问题
- MySQL: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column '
- MySQL报错“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre”
- MySQL报错“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre”
- Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column
- MySQL: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'sss
- Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'userinfo
- mysql遇见Expression #1 of SELECT list is not in GROUP BY clause and contains nonag
- [mysql] Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'lo
- mysql遇见Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre的问题
- Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'userinfo.
- [Err] 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated colum
- [Err] 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated colum
- mysql遇见Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre的问题
- mysql:Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column
- mysql错误:Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'ga