SELECT list is not in GROUP BY clause and contains nonaggregated column
报错如下:
Expression # of SELECT list is not in GROUP BY clause and contains
nonaggregated column ‘sss.month_id’ which is not functionally
dependent on columns in GROUP BY clause; this is incompatible with
sql_mode=only_full_group_by
问题出现的原因:
MySQL 5.7.5及以上功能依赖检测功能。如果启用了ONLY_FULL_GROUP_BY SQL模式(默认情况下),MySQL将拒绝选择列表,HAVING条件或ORDER BY列表的查询引用在GROUP BY子句中既未命名的非集合列,也不在功能上依赖于它们。(5.7.5之前,MySQL没有检测到功能依赖关系,默认情况下不启用ONLY_FULL_GROUP_BY。有关5.7.5之前的行为的说明,请参见“MySQL 5.6参考手册”。)以下解决方案并不是最终解决方案,只是屏蔽了报错,但问题依然存在。如有好的解决方案望告知谢谢!
解决方法一:
打开navcat,
用sql查询:
select @@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
去掉ONLY_FULL_GROUP_BY,重新设置值。
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 配置文件设置
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有any_value(field)函数,他主要的作用就是抑制ONLY_FULL_GROUP_BY值被拒绝
官方有介绍,地址:https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_any-value
我们可以把select语句中查询的属性(除聚合函数所需的参数外),全部放入any_value(field)函数中;
例如:select name,any_value(sex) from test_table group by name
这样sql语句不管是在ONLY_FULL_GROUP_BY模式关闭状态还是在开启模式都可以正常执行,不被mysql拒绝。
SELECT list is not in GROUP BY clause and contains nonaggregated column的更多相关文章
- [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 ...
- 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 ...
- 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 ...
- 【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 ...
- 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 ...
- 记录一次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报错: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 ...
- mysql 8.0下的SELECT list is not in GROUP BY clause and contains nonaggregated column
mysql的版本 mysql> select version();+-----------+| version() |+-----------+| 8.0.12 |+-----------+ 在 ...
- 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 ...
随机推荐
- JAVA设计模式——开篇
设计模式很重要,重要性我就不再复述了.最主要的是,通常我们在写一定量代码后,常用的方法什么的都熟悉后,想再提高代码能力,我找到的最好的方法还是去学习,理解设计模式.不理解设计模式,看一些开源框架和ja ...
- 面试题之(HTTP协议)【转】
转自:http://www.cnblogs.com/ranyonsue/p/5984001.html HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协 ...
- java程序员学C#
因为工作需要,我要学习C#,其实我觉得不错,我喜欢了解更多的语言,因为这对我今后的发展很有帮助,毕竟技多不压身,下面是我今天学习后总结C#的基本语法: 我曾经学过C,而且又是java程序员,所以对我来 ...
- JS数组Sort方法的使用
想用sort方法对数组排下序,代码如下: var nums = "12 645 6 85 81 0 9 365 4 752".split(" ").map(fu ...
- cesium 之自定义气泡窗口 infoWindow 篇
前言 cesium 官网的api文档介绍地址cesium官网api,里面详细的介绍 cesium 各个类的介绍,还有就是在线例子:cesium 官网在线例子,这个也是学习 cesium 的好素材. 自 ...
- 轨迹系列5——验证轨迹GPS坐标转换为本地坐标的四/七参数是否准确的一种方案
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1. 背景 目前对多个项目轨迹不准确的情况做了排查,发现导致轨迹偏移百分 ...
- 牛客网:Java重命名文件
项目介绍 不管是C/C++还是JAVA,都可能生成一些持久性数据,我们可以将数据存储在文件或数据库中,此项目主要训练学习Java对本地磁盘的文件重命名,例如C:\nowcoder.txt重命名C:\n ...
- 关于使用阿里OSS服务搭建图床和使用PicGO上传图片到图床
最近喜欢上了使用markdown来写博客,可是markdown的图片却是本地的,如果我要发博客,那么又要重复截图了.于是干脆弄了个图床,本地截图的时候上传到图床,markdown中的代码结果也是图床里 ...
- macos 常用快捷键及操作
通用: 拷贝相当于window下的复制非苹果键盘(command == win option == alt control == ctrl)Command + C 拷贝(Copy)Command + ...
- 关于sqlserver字符类型查询条件区分大小写
在写sql的查询时 如下: select * from Users where username='WangE' select * from Users where username='wange' ...