MySQL Expression #2 of 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异常处理。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、异常错误

使用联表查询时,group by两个字段出现了错误

expression #2 of select list is not in group by clause and contains nonaggre,mysql,数据库

expression #2 of select list is not in group by clause and contains nonaggre,mysql,数据库

Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'train_c.e.ques_type' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

意思是select字段里包含了没有被group by 条件唯一确定的字段。

二、原因

MySQL版本5.7之后会检测函数依赖,默认启用的模式是ONLY_FULL_GROUP_BY,使用GROUP BY 语句违背了sql_mode=only_full_group_by。该模式的意思是只有确定唯一字段的group by才能执行。

使用SQL查询sql_mode

select @@global.sql_mode

expression #2 of select list is not in group by clause and contains nonaggre,mysql,数据库

三、解决方法

在MySQL-server层面修改sql_mode,在配置文件my.cnf中关闭sql_mode=ONLY_FULL_GROUP_BY
,将sql_mode配置放在 [mysqld] 后

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

expression #2 of select list is not in group by clause and contains nonaggre,mysql,数据库

重启mysqld服务

systemctl restart mysqld.service
systemctl start mysqld.service
systemctl stop mysqld.service

成功

expression #2 of select list is not in group by clause and contains nonaggre,mysql,数据库文章来源地址https://www.toymoban.com/news/detail-821962.html

到了这里,关于MySQL Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column异常处理的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • MySQL 出现 which is not functionally dependent on columns in GROUP BY clause;解决方法

    项目跑到一个新服务器上保存了 一个新安装的数据库,出现了问题 具体报错信息如下: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘aigcc.t2.id’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by 问题出现在grou

    2024年02月08日
    浏览(38)
  • which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mod

    mysql 执行报错 : Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘bcdsystem.cities.city’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by\\\" 1.这个错误发生在mysql 5.7 版本及以上版本会出现的问题: 2.在sql执行时,出现

    2024年02月16日
    浏览(40)
  • mysql group by 字段 与 select 字段

    表数据如下: 执行SQL语句1: SELECT * FROM `z_course` GROUP BY NAME,SEX  结果:   执行SQL语句2: SELECT * FROM `z_course` GROUP BY NAME    sql 1 根据 name,sex 两个字段分组,查询 所有字段,返回结果 sql 2 根据 name 字段分组,查询所有字段,返回结果 sql2 和 sql1 的区别是 分组少了 sex字段,那

    2024年02月10日
    浏览(33)
  • Java异常 #Number of lines annotated by Git is not equal to number of lines in the file, check file …

    在项目中某个 java 文件左边栏右键查看代码版本履历(Annotate)时无法显示,IDEA 提示:Number of lines annotated by Git is not equal to number of lines in the file, check file encoding and line separators.   这个问题涉及到不同操作系统下文本文件的换行符差异引起的。在不同操作系统中,文本文件的

    2024年02月03日
    浏览(35)
  • adb no permissions (user *** is not in the plugdev group)

    首次配置ubuntu下的adb 环境,执行了adb device命令会出现以下问题 尝试了下 sudo ./adb devices 还是一样的错误 可以尝试修改可执行文件  adb 的权限 这样就可以找到设备了。

    2024年02月15日
    浏览(45)
  • MySQL:报错this is incompatible with sql_mode=only_full_group_by

    在mysql 工具 搜索或者插入数据时报下面错误: ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column \\\'database_tl.emp.id\\\' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by 原因: 首先,我们看一下group by的语法

    2024年01月20日
    浏览(42)
  • 解决 Uncaught (in promise) TypeError: list is not iterable 报错

    最近在项目中遇到 Uncaught (in promise) TypeError: list is not iterable 报错,虽然不影响代码运行,但是看着报错感觉有点难受,试试能不能解决它 看了很多篇文章,都是说使用 Object.keys() 可以解决问题 就先使用 Object.keys() 看看,代码运行之后 因为 Object.keys() 传入的是 null 和 undefin

    2024年02月11日
    浏览(43)
  • blocked by CORS policy: Request header field token is not allowed by Access-Control-Allow-Headers in

    uniapp 跨域报错: 原因跨域设置没有设置token名称,将token加入请求跨域请求头里面即可 没设置token前 设置token后 对比差异 加上token即可解决,同理要是需要其他请求头以逗号分隔加上即可

    2024年02月14日
    浏览(34)
  • Component is not found in path “components/xxx/xxx“ (using by “pages/xxx/xxx“) 问题记录

    相信做过小程序的都遇到过Component is not found in path “components/xxx/xxx“ (using by “pages/xxx/xxx“) 这个问题,一般情况的是引用路径有问题,检查代码路径改对就好了,又或者是 分包 影响的 先说一下我得使用场景,不一定适用于所有人,只是记录一下我遇到的 1.小程序是分包的

    2024年02月02日
    浏览(37)
  • 6、hive的select(GROUP BY、ORDER BY、CLUSTER BY、SORT BY、LIMIT、union、CTE)、join使用详解及示例

    1、apache-hive-3.1.2简介及部署(三种部署方式-内嵌模式、本地模式和远程模式)及验证详解 2、hive相关概念详解–架构、读写文件机制、数据存储 3、hive的使用示例详解-建表、数据类型详解、内部外部表、分区表、分桶表 4、hive的使用示例详解-事务表、视图、物化视图、DDL

    2024年02月11日
    浏览(39)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包