数据库多表连接查询中使用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文件解决了复杂的数据库访问的难题.时 ...
随机推荐
- 主题 2 Shell工具和脚本
主题 2 Shell工具和脚本 Shell 工具和脚本 · the missing semester of your cs education (missing-semester-cn.github. ...
- 官网下载CentOS系统镜像过程
想学习CentOS系统,但是不知道镜像去哪里搞,随便去个第三方发现要么要注册,要么各种广告病毒,或者好不容易找到官网,不仅全英文,有些专业术语也不懂,本文说明官网下载自己想要的CentOS镜像整个流程 ...
- 从0-1超详细教你实现前端读取excel表格并渲染到界面
@ 目录 说明 前提 代码仓库 步骤一:准备工作 步骤二:实现导入表格解析 步骤三:实现表格渲染 结语 本文旨在解决无需调用后端接口,实现前端读取表格文件,获取文件内容,渲染到界面的需求 我的其他文章 ...
- SSM进行Query
在查询之前,需要输入数据库字段的名称,s_id需要获取
- Nacos配置中心 (介绍与配置)
Nacos配置中心 当微服务部署的实例越来越多,达到数十.数百时,逐个修改微服务配置就会让人抓狂,而且很容易出错.我们需要一种统一配置管理方案,可以集中管理所有实例的配置. Nacos一方面可以将配置 ...
- Cnblogs博客皮肤开发调试最佳方案
Cnblogs博客园支持自定义js来美化站点(需要申请JS权限),可以将主题托管到自己的云资源或CDN加速节点节点上. 例如我的网站为 www.example.com(IP或其它host),我将编译后 ...
- Visual Studio增加Class类顶部签名描述信息
1. 找到安装路径 默认在 C:\Program Files (x86)\Microsoft Visual Studio\,然后进入到2019\Professional\Common7\IDE\Ite ...
- 《关于我因为flink成为spark源码贡献者这件小事》
各位读者老爷请放下手上的板砖,我可真没有标题党,且容老弟慢慢道来. spark和flink本身相信我不用做过多的介绍,后端同学不管搞没搞过大数据,应该都多多少少听过. 如果没听过,简单说,spark和 ...
- 为什么sleeping的会话会造成阻塞(2)
背景 客户反馈系统突然从11:10开始运行非常缓慢,在SQL专家云中看到大量的产生阻塞的活动会话,KILL掉阻塞的源头马上又出现新的源头,实在没有办法只能重启应用程序断开所有数据库连接才解决,请我们协 ...
- JZOJ 3527.迷宫花坛(garden)
题面 思路 考场想到 \(tarjan\) 缩点 然而忘了缩点怎么打 于是甩了个暴力 改题时学了个圆方树 发现挺好用 于是······注意重边 \(Code\) #include<cstdio& ...