环境:mysql-8.0.15-winx64

问题描述:

Error querying database.  Cause: java.sql.SQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'tt.from_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

关于叶神的头条资讯网站项目,自己在练习时,写了一个站内信,却一直获取站内信列表失败。前后对照代码都没错,很是急人!然后用MySQL workbench图示化出来发现,在写以下SQL语句时就出现了错误。对照着IDEA上的出错警示(下图1所示)

SELECT * FROM message group by conversation_id;

图1. IDEA上的出错警示

果然是DAO层的SQL语句出现了问题。但是我回过头来看,再三检查,发现明明没有问题呢【黑人问号脸】,于是百度搜索,发现真有不少相关的问题。

原来代码没错,是数据库的sql_mode出了问题。

参照参考2中解释【真心详细】,SQL模式默认情况下是only_full_group_by ,MySQL就会拒绝选择列表、条件或顺序列表引用的查询,这些查询将引用组中未命名的非聚合列,而不是在功能上依赖于它们。

为了一探究竟,于是乎,先后照着执行以下命令:

SHOW SESSION VARIABLES;
SHOW GLOBAL VARIABLES;
select @@sql_mode;

可见:session和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

按照参考2中解决办法操作时,在命令行发现出现了问题

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';

发现提示sql_mode不能被赋值为NO_AUTO_CREATE_USER,操作了一下set session sql_mode,也是同样的问题。

于是乎,那不行就不行呗,将NO_AUTO_CREATE_USER删去了,再次赋值。果然成功!

正确执行命令是:

set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
mysql> set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

这两个命令是去掉 sql_mode 的 ONLY_FULL_GROUP_BY模式的。故有效果。

另外,我还试了参考1中的办法,就是高赞的答案,执行如下:

SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

然后发现也是不行,所以建议大家还是采用参考2中的方法吧!

参考:

1. https://stackoverflow.com/questions/41887460/select-list-is-not-in-group-by-clause-and-contains-nonaggregated-column-inc

2. 极力推荐:https://blog.csdn.net/fansili/article/details/78664267

3. http://blog.sina.com.cn/s/blog_3eba8f1c0102x75o.html

Error Code: 1055.Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'userinfo.的更多相关文章

  1. MYSQL报错:1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column

    1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'rpa ...

  2. mysql升级后出现Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'userinfo.

    安装了mysql5.7,用group by 查询时抛出如下异常: Expression #3 of SELECT list is not in GROUP BY clause and contains ...

  3. Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'userinfo.

    安装了mysql5.7,用group by 查询时抛出如下异常: Expression # of SELECT list is not in GROUP BY clause and contains ...

  4. 解决大于5.7版本mysql的分组报错Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'userinfo.

    前言: 借鉴网址:https://blog.csdn.net/fansili/article/details/78664267 原因:  MySQL 5.7.5和up实现了对功能依赖的检测.如果启用了 ...

  5. 【mybatis】【mysql】mybatis查询mysql,group by分组查询报错:Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column

    mybatis查询mysql,group by分组查询报错:Expression #1 of SELECT list is not in GROUP BY clause and contains no ...

  6. 记录一次mysql由5.6升级到5.7出现的异常---Expression #23 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'c.commentCount' which is not functionally dependent on columns in GROUP BY clause;

    ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expre ...

  7. Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column

    Error: javax.servlet.ServletException: java.sql.SQLSyntaxErrorException: Expression #4 of SELECT lis ...

  8. [mysql] Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'loser.tank_admin.login_ip' which is not functionally dependent on columns in GROUP BY clause; this is

    执行SQL: SELECT login_name,login_ip,sex FROM tank_admin GROUP BY login_name ; 时抛出异常. Expression #2 of ...

  9. Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'blog.t_blog.addTime' which is not functi

    sql报错: Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of SELECT ...

随机推荐

  1. Python编程小技巧(一)

    在使用Tkinter编写代码的时候,有时候会忘记某个组件的参数是什么或者忘记某个参数怎么拼写的,此时可以通过如下方式查询组件的参数列表,以按钮组件为例: 1 # -*- coding:utf-8 -* ...

  2. php压缩文件夹并下载到本地

    /** * @param $path 要压缩的文件夹路径 * @param $filename 要生成的压缩包名称 */ public function create_zip($path,$filen ...

  3. three.js cannon.js物理引擎之Heightfield

    今天郭先生说一说cannon.js物理引擎之Heightfield高度场,学过场论的朋友都知道物理学中把某个物理量在空间的一个区域内的分布称为场,高度场就是与高度相关的场,而cannon.js物理引擎 ...

  4. windows ping bat脚本

    参考百度链接:https://zhidao.baidu.com/question/577024998.html 要求:1.从同级目录下读取iplist.txt文件内的ip/域名列表(每行一个):2.对 ...

  5. Building a high performance JSON parser

    Building a high performance JSON parser https://dave.cheney.net/high-performance-json.html

  6. 【c++小知识】static用法浅析

    一.前言 C++的关键字static分两种用法,在面向过程程序设计(c语言中的普通变量和函数)中的使用和在面向对象程序设计(c++中的类)中的使用 二.面向过程程序设计中的static(静态变量.静态 ...

  7. JAXB学习(二): 对JAXB支持的主要注解的说明

    我们在上一篇中对JAXB有了一个大致的认识,现在我们来了解JAXB的一些主要注解. 顶层元素:XmlRootElement 表示整个XML文档的类应该使用XmlRootElement修饰,其实就像之前 ...

  8. ASP.NET Core 5.0 MVC中的 Razor 页面 介绍

    Razor 是一个用于将基于服务器的代码嵌入到网页中的标记语法. Razor语法由 Razor 标记.c # 和 HTML 组成. 通常包含 Razor 的文件的扩展名 cshtml Razor 语法 ...

  9. [每日电路图] 12、带自动烧写能力的 ESP8266 开发板制作

    目录 前言 1.芯片先关信息 2.原理图介绍 2.1 供电电路 2.2 串口电路 2.3 自动烧写电路 3.PCB 效果展示 附录 前言 ESP8266 是乐鑫公司面向物联网应用的高性价比.高度集成的 ...

  10. 急~为啥我指定的的maven依赖版本没有生效?不是最短路径原则吗?

    女朋友他们项目用了 spring-boot,以 spring-boot-parent 作为 parent: <parent> <groupId>org.springframew ...