博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
13.11. this is incompatible with sql_mode=only_full_group_by
阅读量:5876 次
发布时间:2019-06-19

本文共 2263 字,大约阅读时间需要 7 分钟。

ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'mydb.contact.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

mysql> select @@version;+-----------+| @@version |+-----------+| 5.7.10    |+-----------+1 row in set (0.00 sec)mysql> select @@GLOBAL.sql_mode;+-------------------------------------------------------------------------------------------------------------------------------------------+| @@GLOBAL.sql_mode                                                                                                                         |+-------------------------------------------------------------------------------------------------------------------------------------------+| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |+-------------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec)mysql> SET sql_mode = '';Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> select id,name from contact group by name limit 10;+-------+-------------+| id    | name        |+-------+-------------+| 84046 |   张伟      || 80259 |   张磊      ||   784 |   王岩      || 87685 |  杨钞       |+-------+-------------+10 rows in set (0.07 sec)

不建议设置 SET sql_mode = '',正确方式如下:

mysql> set global 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> set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

或者采用

Adding only one mode to sql_mode without removing existing ones:SET sql_mode=(SELECT CONCAT(@@sql_mode,',
'));Removing only a specific mode from sql_mode without removing others:SET sql_mode=(SELECT REPLACE(@@sql_mode,'
',''));In your case, if you want to remove only ONLY_FULL_GROUP_BY mode, then use below command:SET sql_mode=(SELECT REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY', ''));

原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

你可能感兴趣的文章
开发进度——4
查看>>
JS里验证信息
查看>>
Akka actor tell, ask 函数的实现
查看>>
windows10 chrome 调试 ios safari 方法
查看>>
Netty 4.1.35.Final 发布,经典开源 Java 网络服务框架
查看>>
详解Microsoft.AspNetCore.CookiePolicy
查看>>
SCDPM2012 R2实战一:基于SQL 2008 R2集群的SCDPM2012 R2的安装
查看>>
SQL SERVER中字段类型与C#数据类型的对应关系
查看>>
Linux lsof命令详解
查看>>
SVG path
查看>>
js判断checkbox是否选中
查看>>
多系统盘挂载
查看>>
MySQL函数怎么加锁_MYSQL 函数调用导致自动生成共享锁问题
查看>>
MR1和MR2的工作原理
查看>>
Eclipse中修改代码格式
查看>>
GRUB Legacy
查看>>
关于 error: LINK1123: failure during conversion to COFF: file invalid or corrupt 错误的解决方案...
查看>>
python实现链表
查看>>
java查找string1和string2是不是含有相同的字母种类和数量(string1是否是string2的重新组合)...
查看>>
Android TabActivity使用方法
查看>>