数据库多表连接查询中使用group by分组语句,Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'XXX' which is not functionally dependent on columns in GROUP BY claus
需求描述:
要是用两表联合查询,并对查询的结果进行分组:sql如下:
1 SELECT
2 a.`id`,
3 a.`fr_num`,
4 b.`ent_status`
5 FROM
6 `table1` a
7 LEFT JOIN `table2` b
8 ON b.`fr_id` = a.`id`
9 GROUP BY b.`fr_num`
这样的sql语句会报错结果如下:
Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'a.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by.
问题处理:
首先了解一下sql的group by的用法:
1、select后面的查询字段要么在group by后,要么是聚合函数
2、如果有条件对结果进行筛选,有两种方式:(1) 先使用where + 条件,然后使用group by (2) 先使用group by,然后使用having进行结果筛选
解决:结合group by 的使用方法对sql进行改进就ok了~
数据库多表连接查询中使用group by分组语句,Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'XXX' which is not functionally dependent on columns in GROUP BY claus的更多相关文章
- 记录一次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] 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 ...
- Access数据库多表连接查询
第一次在Access中写多表查询,就按照MS数据库中的写法,结果报语法错,原来Access的多表连接查询是不一样的 表A.B.C,A关联B,B关联C,均用ID键关联 一般写法:select * fro ...
- mysql 执行报错:Error querying database. Cause: java.sql.SQLSyntaxErrorException: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 版本及以上版本会出现的问题: mysql 5.7版本默认的sql配置是:sql_mode="ONLY_FULL_GROUP_BY",这个配置严 ...
- 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 GROUP BY clause
解决方法一: SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); 优点:不用重启mysql 缺点:重启mysql后还会 ...
- Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'kindergarten.n.stuMChkTime' which is not functionally dependent on columns in GROUP BY clause; this is in
错误原因: sql _mode中only _full _group _by不兼容的问题 解决思路: 既然是only _full _group _by不兼容,那就把它去掉就好啦 show var ...
- 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 GROUP BY clause; this
最近使用新版本的mysql,执行语句的时候报错.网上找了一下,解决方法如下: vim /etc/mysql/conf.d/mysql.cnf [mysqld] sql_mode=STRICT_TRAN ...
- 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 ...
- 010.简单查询、分组统计查询、多表连接查询(sql实例)
-------------------------------------day3------------ --添加多行数据:------INSERT [INTO] 表名 [(列的列表)] --SEL ...
- MybatisPlus多表连接查询
一.序言 (一)背景内容 软件应用技术架构中DAO层最常见的选型组件为MyBatis,熟悉MyBatis的朋友都清楚,曾几何时MyBatis是多么的风光,使用XML文件解决了复杂的数据库访问的难题.时 ...
随机推荐
- [编程基础] Python列表解析总结
在本教程中,我们将学习使用Python列表解析(list comprehensions)相关知识 1 使用介绍 列表解析是一种基于现有列表创建列表的句法结构.列表解析提供了创建列表的简洁方法.通常需要 ...
- CVE-2007-4556 s2-001
漏洞名称 S2-001 远程代码执行 利用条件 WebWork 2.1 (with altSyntax enabled), WebWork 2.2.0 - WebWork 2.2.5, Struts ...
- linux 基础(2) 文件权限及其修改
文件的权限属性 在 linux 中,每个文件都有唯一的"所属者"(user)和"所属群组"(group).owner 和 group 都对文件有特殊的权限 输入 ...
- 踩坑实录---Angular防抖——点击事件
npx ng g directive DebounceClickDirective --module=app 然后自动生成了2 个文件 CREATE src/app/debounce-click-di ...
- 万字详解,吃透 MongoDB!
本文已经收录进 JavaGuide(「Java学习+面试指南」一份涵盖大部分 Java 程序员所需要掌握的核心知识.) 少部分内容参考了 MongoDB 官方文档的描述,在此说明一下. MongoDB ...
- File、FileReader、Base64、Blob基本使用以及Buffer、ArrayBuffer之间的转换
File文件 (File)对象获取文件的信息.实际上,File 对象是特殊类型的 Blob,Blob 的属性和方法都可以用于 File 对象.在js中,一般通过input元素,点击上传文件成功之后返回 ...
- 12月8日内容总结——Django推导流程,Django模块的下载和基本使用、Django的应用和目录结构讲解、Django三板斧
目录 一.纯手撸web框架 二.基于wsgiref模块 三.代码封装优化 四.动静态网页 五.jinja2模块 六.前端.后端.数据库三者联动 七.python主流web框架 八.django简介 1 ...
- Monkey 命令
1) 参数: -p 参数-p用于约束限制,用此参数指定一个或多个包(Package,即App).指定 包之后,Monkey将只允许系统启动指定的APP.如果不指定包,Monkey将允许系统启动设备中 ...
- drf-drf请求、响应、基于GenericAPIView+5个视图扩展类
1.反序列化类校验部分源码分析(了解) 1.当我们在视图类中生成一个序列化类对象ser,并且用ser.is_valid()是就会执行校验,校验通过返回True,不通过返回False.首先对象ser和序 ...
- python学习day 02
昨日内容回顾 typora软件 1.作为一款逐年火爆的文本编辑器,深受IT行业的喜爱. 2.下载与安装: windows用群里发的软件 macOS下载地址:https://mac.qdrayst.co ...