Expression #7 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'invoicecertify.goods.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

问题:

select sum(goods.je) je,sum(goods.se) se, goods.hwmc hwmc,goods.zclx zclx ,goods.zcsq zcsq, invoice.state state
,goods.id id,invoice.ref_company_id ref_company_id
from in_goods_detail goods join in_invoice_certification invoice
on invoice.code = goods.code and invoice.number = goods.number
WHERE invoice.cert_state = 3
and (goods.zcsq is null or goods.zcsq = '2017-09')
and ref_company_id = 2107
group by invoice.state,goods.hwmc,goods.zclx,goods.zcsq

测试环境可以用,演示环境不可以用???select version() 不一致,sql_mode 不同

Database changed

mysql>

mysql>   set @@GLOBAL.sql_mode='';

Query OK, 0 rows affected, 1 warning (0.00 sec)

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

Query OK, 0 rows affected (0.00 sec)

以下为copy:

mysql命令gruop by报错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的语法:
select 选取分组中的列+聚合函数 from 表名称 group by 分组的列 
从语法格式来看,是先有分组,再确定检索的列,检索的列只能在参加分组的列中选。
我当前Mysql版本5.7.17,
再看一下ONLY_FULL_GROUP_BY的意思是:对于GROUP BY聚合操作,如果在SELECT中的列,没有在GROUP BY中出现,那么这个SQL是不合法的,因为列不在GROUP BY从句中,也就是说查出来的列必须在group by后面出现否则就会报错,或者这个字段出现在聚合函数里面。
 
查看mysql版本命令:select version();
查看sql_model参数命令:
SELECT @@GLOBAL.sql_mode;
SELECT @@SESSION.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,
 
解决方法:
1.只选择出现在group by后面的列,或者给列增加聚合函数;(不推荐)
2.命令行输入:
set @@GLOBAL.sql_mode='';
set sql_mode ='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!
 
这个时候 在用工具select 一下
SELECT @@sql_mode;
SELECT @@GLOBAL.sql_mode;
 
发现已经不存在ONLY_FULL_GROUP_BY ,感觉已经OK。但是如果你重启Mysql服务的话,发现ONLY_FULL_GROUP_BY还是会存在的
 
想要彻底解决这个问题 就得去改my.ini 配置(如果你们mysql 没有这个文件,就把my-default.ini 改成my.ini,我这个版本就是没有my.ini配置问题)
 
在 [mysqld]和[mysql]下添加
SET 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=only_full_group_by配置的更多相关文章

  1. 【Solution】MySQL 5.8 this is incompatible with sql_mode=only_full_group_by

    [42000][1055] Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated colu ...

  2. MySQL查询语句报错 sql_mode=only_full_group_by 问题

    升级MySQL到5.7后,查询语句总是报sql_mode=only_full_group_by问题,总结归纳了两种解决方案,推存第二种解决方案. 报错信息: [Err] 1055 - Expressi ...

  3. MySQL sql_mode=only_full_group_by错误

    今天在测试服务器上突然出现了这么一个MySQL的问题,同样的代码正式服没有问题,那肯定就是出在了配置上,查了一下原因才明白原来是数据库版本为5.7以上的版本, 默认是开启了 only_full_gro ...

  4. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: ..... this is incompatible with sql_mode=only_full_group_by

    一.异常信息 org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: com.mysq ...

  5. mysql命令gruop by报错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 ...

  6. 最近升级mysql5.7出现下面问题,ORDER BY clause is not in GROUP BY..this is incompatible with sql_mode=only_full_group_by

    执行sql: SELECT * FROM `user_link` WHERE `group_id` IN ('78', '79') GROUP BY `link_id` 报错: SQLSTATE[42 ...

  7. MYSQL 版本5.7.24 sql_mode=only_full_group_by问题

    具体出错提示: [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggr ...

  8. mysql报错this is incompatible with sql_mode=only_full_group_by

    1.报错信息 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: In aggregated query without GROUP ...

  9. mysql5.7 this is incompatible with sql_mode=only_full_group_by错误

    解决办法: https://blog.csdn.net/qq_42175986/article/details/82384160 前言: 一.原理层面 这个错误发生在mysql 5.7 版本及以上版本 ...

随机推荐

  1. 【Leetcode】378. Kth Smallest Element in a Sorted Matrix

    Question: Given a n x n matrix where each of the rows and columns are sorted in ascending order, fin ...

  2. [转帖]LNMP组件安装

    https://lnmp.org/install.html 系统需求: CentOS/RHEL/Fedora/Debian/Ubuntu/Raspbian/Deepin/Aliyun/Amazon/M ...

  3. [转帖]Kubernetes及容器编排的总体介绍【译】

    Kubernetes及容器编排的总体介绍[译] 翻译自The New Stack<Kubernetes 生态环境>作者:JANAKIRAM MSV和 KRISHNAN SUBRAMANIA ...

  4. vue 请求后台数据2(copy)

    https://blog.csdn.net/vergilgeekopen/article/details/68954940 需要引用vue-resource 安装请参考https://github.c ...

  5. aop 切点匹配规则

  6. 【设计模式】—— 装饰模式Decorator

    前言:[模式总览]——————————by xingoo 模式意图 在不改变原来类的情况下,进行扩展. 动态的给对象增加一个业务功能,就功能来说,比生成子类更方便. 应用场景 1 在不生成子类的情况下 ...

  7. luogu1083 [NOIp2012]借教室 (二分答案+差分)

    先二分一个答案x,然后通过差分来看有没有不满足的 #include<bits/stdc++.h> #define pa pair<int,int> #define lowb(x ...

  8. 滥用基于资源约束委派来攻击Active Directory

    0x00 前言 早在2018年3月前,我就开始了一场毫无意义的争论,以证明TrustedToAuthForDelegation属性是无意义的,并且可以在没有该属性的情况下实现“协议转换”.我相信,只要 ...

  9. 【洛谷P1101】单词方阵

    题目大意:给一 \(n \times n\) 的字母方阵,内可能蕴含多个 \("yizhong"\) 单词.单词在方阵中是沿着同一方向连续摆放的.摆放可沿着 8 个方向的任一方向, ...

  10. 9:@RequestMapping 用法详解之地址映射

    引言: 前段时间项目中用到了RESTful模式来开发程序,但是当用POST.PUT模式提交数据时,发现服务器端接受不到提交的数据(服务器端参数绑定没有加任何注解),查看了提交方式为applicatio ...