【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 nonaggregated column
mysql版本是5.7
1.导致出错的sql语句是:
<select id="findScNumByTime" parameterType="com.pisen.cloud.luna.ms.security.code.api.beans.ScNumCountBean"
resultType="com.pisen.cloud.luna.ms.security.code.api.beans.ScNumCountBean"> SELECT
create_date queryDate,
IFNULL(sum(security_code_total), 0) createSCNum,
IFNULL(sum(print_num), 0) printNum
FROM
security_code_config
WHERE
tid = #{tid}
AND
DATE_FORMAT(create_date,#{queryDateFormat}) <= DATE_FORMAT(#{endDate},#{queryDateFormat})
AND
DATE_FORMAT(create_date,#{queryDateFormat}) >= DATE_FORMAT(#{startDate},#{queryDateFormat})
GROUP BY
DATE_FORMAT(create_date,#{queryDateFormat})
</select>
即:
SELECT
create_date queryDate,
IFNULL(sum(security_code_total), 0) createSCNum,
IFNULL(sum(print_num), 0) printNum
FROM
security_code_config
WHERE
tid = 'test_tenement_123'
AND
DATE_FORMAT(create_date,'%Y-%m') <= DATE_FORMAT('2019-03-12','%Y-%m')
AND
DATE_FORMAT(create_date,'%Y-%m') >= DATE_FORMAT('2018-10-01','%Y-%m')
GROUP BY DATE_FORMAT(create_date,'%Y-%m')
2.导致出错的原因是因为:
请在mysql执行:
SHOW SESSION VARIABLES;
和
SHOW GLOBAL VARIABLES;
都可以看到:

错误原因就是这里:
only_full_group_by
要求select的列都要在group里面。
在mysql5.5没有这个问题!!!
3.解决方法:
分别执行
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'
和
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'
注意先执行session的修改,再执行global的修改!!!!
修改完成后,再查看【执行第二步的两个sql查看即可】

4.最后,需要你重启spring boot服务,再进行查询调用,才会有效
【自己测试的情况就是,未重启mysql服务,重启了spring boot服务,再调用就可以正常执行了】
【mybatis】【mysql】mybatis查询mysql,group by分组查询报错:Expression #1 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
环境:Server version: 5.7.27-0 ubuntu 18.04.1 (Ubuntu) 执行分组语句:select * from pet group by owner;时报错: mys ...
- 解决大于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实现了对功能依赖的检测.如果启用了 ...
- [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 ...
- mysql group by分组查询后 查询个数
mysql group by分组查询后 查询个数2个方法随便你选 <pre>select count(distinct colA) from table1;</pre>< ...
- mysql使用group by分组时出现错误ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and
问题: 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ...
- 记录一次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 ...
- mysql问题解决SELECT list is not in GROUP BY clause and contains nonaggregated column
今天在Ubuntu下的部署项目,发现一些好好的列表页面发生 :Expression # of SELECT list is not in GROUP BY clause and contains no ...
- 解决MySQL报错:1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'informat
解决MySQL报错:1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'informat ...
- mysql [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GRO
[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated c ...
随机推荐
- 一些对外的服务(例如lnmp)都不用root执行
lnmp lamp等需要对外的服务,都不用root用户执行进程 缺点: 如果php程序使用root运行,万一你的程序有漏洞,被拿到了web shell,那么黑客将直接拥有root权限进入你的系统 对于 ...
- centos7执行 wget命令: command not found的两种解决方法
1.rpm 安装 下载wget的RPM包: http://mirrors.163.com/centos/6.8/os/x86_64/Packages/wget-1.12-8.el6.x86_64.rp ...
- [转]mysql性能优化-慢查询分析、优化索引和配置
一. 优化概述 MySQL数据库是常见的两个瓶颈是CPU和I/O的瓶颈,CPU在饱和的时候一般发生在数据装入内存或从磁盘上读取数据时候.磁盘I/O瓶颈发生在装入数据远大于内存容量的时候,如果应用分布在 ...
- 模板引擎--hogan
学习地址:https://www.imooc.com/article/18493 Hogan的github地址镇楼:https://github.com/twitter/hogan.js
- java实现xml格式与javabean之间的转换XmlUtil类
XmlUtil类:不多说,直接撸代码: /** * java 转换成xml * @Title: toXml * @Description: TODO * @param obj 对象实例 * @retu ...
- 【转】MySQL安全配置介绍
一.前言 很多文章中会说,数据库的权限按最小权限为原则,这句话本身没有错,但是却是一句空话.因为最小权限,这个东西太抽象,很多时候你并弄不清楚具体他需要哪些权限. 现在很多mysql用着root账户在 ...
- IntelliJ IDEA :Error:(1, 1) java: 非法字符: '\ufeff'
将file encodings由utf-8改成utf-16,再将utf-16改成utf-8就好了
- .NetCore源码阅读笔记系列之Security (一) Authentication & AddCookie
如果你使用过.NetCore开发过程序,你会很清楚,在其中我们经常会用到一些如下的代码 services.AddAuthentication(options => { options.Defau ...
- Struts2与Spring的Maven依赖冲突
今天在用Maven集成Struts2+Spring+Hibernate时发现只要不在web模块中声明spring-web的依赖,就会报java.lang.NoClassDefFoundError: [ ...
- node.js之nodemon 代码热更新 修改代码后服务器自动重启
1.安装nodemon: npm install -g nodemon //全局安装 npm install nodemon --save //局部安装 2.在项目根目录下创建 nodemon.jso ...