【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 ...
随机推荐
- 转 Spring Boot之No session repository could be auto-configured, check your configuration问题解决
1. 环境介绍 JDK 1.8 Spring-Boot 1.5.1.RELEASE, STS IDE 2. 问题的提出 创建了一个非常简约的Spring Boot Web Application ...
- SUSE Enterprise Server 12 SP3 64 设置防火墙开放8080端口,出现Unsafe permissions for file /etc/sysconfig/SuSEfirewall2 to be sourced
SUSE Enterprise Server 12 SP3 64 设置防火墙开放8080端口时出现 Unsafe permissions for file /etc/sysconfig/SuSEf ...
- jenkins免密添加SSH Servers
在配置ssh server时可以使用用户名秘密的方式登录,但有点不安全,只要有权限配置jenkins服务器的人就可以看到密码.所以可以利用ssh免密登录的方式链接ssh server. 1.在jenk ...
- ldconfig命令与ldd命令
ldconfig是一个动态链接库管理命令,为了让动态链接库为系统所共享,还需运行动态链接库的管理命令 ldconfig通常在系统启动时运行,而当用户安装了一个新的动态链接库时,就需要手工运行这个命令. ...
- java Set(集合)
set不保存重复的元素(至于如何判断元素相同则较为复杂,后面将会看到).Set中最常被使用的是测试归属表,你可以很容易地询问某个对象是否在某个Set中,正因如此,查找就成了Set最重要的操作,因此通常 ...
- ajax最基础入门
1.介绍 AJAX = 异步 JavaScript 和 XML. AJAX 是一种用于创建快速动态网页的技术. 通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.这意味着可以在不重 ...
- k8s的imagePullSecrets如何生成及使用
如果公司的docker仓库(harbor),需要用户认证之后,才能拉取镜像. 那如何在k8s里生成这个secret呢? 这个secret如何还原呢? 在k8s的yaml文件里如何实现呢? 这里提供几个 ...
- [java] DOS编译 .java 文件得到 .class 文件 并执行 以及使用外部 .jar包 时的命令
当写一个java文件后,在DOS中进行编译与执行时,如果没有引入外来的包,那情况很简单 例如: public class hello_world { public static void main(S ...
- Javascript数据类型转换规则
前言 Javascript有7种数据类型,包括5种原始类型(也叫原始值)number.Boolean.string.null.undefined和2种复合类型object.array,它们之间可以根据 ...
- 5969 [AK]刻录光盘
题目描述 Description • 在FJOI2010夏令营快要结束的时候,很多营员提出来要把整个夏令营期间的资料刻录成一张光盘给大家,以便大家回去后继续学习.组委会觉得这个主意不错!可是组委会一时 ...