[Err] 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated colum

Posted wgchen~

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Err] 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated colum相关的知识,希望对你有一定的参考价值。

场景

 [SQL] select * from `crmre` group by `repeat_type_id`;

[Err] 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘crmre.id’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

解决方案

一、查询mysql 相关mode

show variables like '%sql_mode%'

二、show variables like '%sql_mode%' 命令查询,发现里面有 ONLY_FULL_GROUP_BY , 将其删除掉。

三、在把:sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

复制到

四、重启MySQL
service mysqld stop 停止mysql服务命令
service mysqld start 启动mysql服务命令

MySQL 的 sql_mode 模式

MySQL数据库的中有一个环境变量sql_mode,定义了MySQL应该支持的sql语法,数据校验等!

我们可以通过以下方式查看当前数据库使用的sql_mode

一,sql_mode 值的含义

ONLY_FULL_GROUP_BY

对于GROUP BY聚合操作,如果在SELECT中的列,没有在GROUP BY中出现,那么将认为这个SQL是不合法的,因为列不在GROUP BY从句中

STRICT_TRANS_TABLES

在该模式下,如果一个值不能插入到一个事务表中,则中断当前的操作,对非事务表不做任何限制

NO_ZERO_IN_DATE

在严格模式,不接受月或日部分为0的日期。如果使用IGNORE选项,我们为类似的日期插入'0000-00-00'。在非严格模式,可以接受该日期,但会生成警告。

NO_ZERO_DATE

在严格模式,不要将 '0000-00-00'做为合法日期。你仍然可以用IGNORE选项插入零日期。在非严格模式,可以接受该日期,但会生成警告

ERROR_FOR_DIVISION_BY_ZERO

在严格模式,在INSERT或UPDATE过程中,如果被零除(或MOD(X,0)),则产生错误(否则为警告)。如果未给出该模式,被零除时MySQL返回NULL。如果用到INSERT IGNORE或UPDATE IGNORE中,MySQL生成被零除警告,但操作结果为NULL。

NO_AUTO_CREATE_USER

防止GRANT自动创建新用户,除非还指定了密码。

NO_ENGINE_SUBSTITUTION

如果需要的存储引擎被禁用或未编译,那么抛出错误。不设置此值时,用默认的存储引擎替代,并抛出一个异常。

以上是关于[Err] 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated colum的主要内容,如果未能解决你的问题,请参考以下文章

[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause 的问题 MySQL

解决[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause 的问题 MySQL

[Err] 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated colum

[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated

mysql错误:[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggr

MySQL5.7:[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains