需求描述:

  要是用两表联合查询,并对查询的结果进行分组: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的更多相关文章

  1. 记录一次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 ...

  2. [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 ...

  3. Access数据库多表连接查询

    第一次在Access中写多表查询,就按照MS数据库中的写法,结果报语法错,原来Access的多表连接查询是不一样的 表A.B.C,A关联B,B关联C,均用ID键关联 一般写法:select * fro ...

  4. 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",这个配置严 ...

  5. 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后还会 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 010.简单查询、分组统计查询、多表连接查询(sql实例)

    -------------------------------------day3------------ --添加多行数据:------INSERT [INTO] 表名 [(列的列表)] --SEL ...

  10. MybatisPlus多表连接查询

    一.序言 (一)背景内容 软件应用技术架构中DAO层最常见的选型组件为MyBatis,熟悉MyBatis的朋友都清楚,曾几何时MyBatis是多么的风光,使用XML文件解决了复杂的数据库访问的难题.时 ...

随机推荐

  1. ArcGIS工具 - 按字段分割图层

    天下大势,合久必分,分久必合.合并.分割在GIS数据处理和管理中也十分常见,例如按行政区划名称导出多个区县行政图层.按地类名称导出多个地类图层. 功能说明 其实,在ArcGIS中除了按属性导出外,最接 ...

  2. [WPF]颜色主题功能

    效果 点击选择皮肤颜色 代码 public enum Themes { Blue, Gray, Orange } /// <summary> /// 主题颜色管理类 /// </su ...

  3. Mac上安装brew的那些坑

    macOS11.1 入坑! 网上看了一下午的帖子,包括官网,重装command line tool,修改brew_install文件,报错443,Faild during:git getch错误 脱坑 ...

  4. 使用Rancher管理K3s

    rancher中国镜像站地址 https://rancher-mirror.oss-cn-beijing.aliyuncs.com/ https://rancher-mirror.rancher.cn ...

  5. flutter 1.升级2.X在模型类中序列化JSON报错Non-nullable instance field 'title' must be initialized.

    flutter 1.升级2.X在模型类中序列化JSON报错 Non-nullable instance field 'title' must be initialized. Try adding an ...

  6. 多行文字自动换行居中--实测好用的很OK

    实测好用的很~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  7. 迁移学习(DIFEX)《Domain-invariant Feature Exploration for Domain Generalization》

    论文信息 论文标题:Domain-invariant Feature Exploration for Domain Generalization论文作者:Wang Lu, Jindong Wang, ...

  8. 如何又快又好实现 Catalog 系统搜索能力?火山引擎 DataLeap 这样做

      摘要 DataLeap 是火山引擎数智平台 VeDI 旗下的大数据研发治理套件产品,帮助用户快速完成数据集成.开发.运维.治理.资产.安全等全套数据中台建设,降低工作成本和数据维护成本.挖掘数据价 ...

  9. 图解B树及C#实现(3)数据的删除

    目录 前言 从叶子节点删除数据 从非叶子节点删除数据 提前扩充只有 t-1 的 Item 的节点:维持 B树 平衡的核心算法 从左兄弟节点借用 Item 从右兄弟节点借用 Item 与左兄弟节点或者右 ...

  10. ssh 连接 wsl2

    修改ssh相关config https://cloud.tencent.com/developer/article/1538305 其中,端口可以设置成 2222 以防万一 然后在wsl 中执行如下命 ...