Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >解决Mysql在查询时报:1055分组查询错误的解决方法

解决Mysql在查询时报:1055分组查询错误的解决方法

作者头像
星辰sea
发布于 2022-10-29 01:49:06
发布于 2022-10-29 01:49:06
1.4K00
代码可运行
举报
文章被收录于专栏:星辰SEA星辰SEA
运行总次数:0
代码可运行

1. SQL#

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
SELECT name,phone FROM sys_user
GROUP BY name HAVING COUNT(1) >= 2

2. 错误

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
> 1055 - Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'gas_web_gb.B.parent_module_code' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
> 时间: 0.008s

3. 原因

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
是由于默认的 MySQL 配置中 sql_mode 配置了 only_full_group_by,需要 GROUP BY 中包含所有 在 SELECT 中出现的字段。

4. only_full_group_by:使用这个就是使用和oracle一样的group 规则, select的列都要在group中,或者本身是聚合列(SUM,AVG,MAX,MIN) 才行。

5. 使用 SQL 语句可以查询这个配置

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
SELECT @@sql_mode;

6. 解决

如果是Linux,就在配置文件(my.cnf)中修改 sql_mode 的配置(在/etc/my.cnf路径下)。如果是Windows,就修改配置文件my.ini,我的是Windows,如下所示:

7. 重启服务就好了

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022/01/22 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
mysql5.7 group by语法 1055
1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'information_schema.ENGINES.ENGINE' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
陈灬大灬海
2019/07/03
1.4K0
mysql5.7 group by语法 1055
解决mysql 1055错误
情景摘要 今天写了个非id 的group by,结果提示1055 sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1055, "Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'heanny.map_cameras.id' which is not functionally dependent on colum
一朵灼灼华
2022/08/05
1.5K0
已解决:mysql报错:1055 - this is incompatible with sql_mode=only_full_group_by
[Err] 1055 - Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'tase1.ai.home_url' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
陈哈哈
2020/07/06
5.1K0
MySQL报错1055 - Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated colu
1055 - Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'fbjs.mscc.ContactTime' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by, Time: 0.000000s
JaneYork
2023/10/11
6010
MySQL报错1055 - Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated colu
ERROR 1055 (42000): Expression #1 of SELECT list is not in
字面意思理解是sql_model=only_full_group_by限制了,导致在以往MYSQL版本中能正常查询的SQL,在5.7不能用了
码农编程进阶笔记
2021/07/20
1.5K0
分组查询时,select的字段是否一定要都在group by中?
分组查询关键字group by通常和集合函数(MAX、MIN、COUNT、SUM、AVG)一起使用,它可以对一列或者多列结果集进行分组。例如要统计超市水果的种类,需要用count函数,要统计哪个水果价格最高,要用MAX()函数。
MySQL数据库技术栈
2020/08/04
6.7K0
MySQL5.7版本sql_mode=only_full_group_by问题解决办法
原因分析:MySQL5.7版本默认设置了 mysql sql_mode = only_full_group_by 属性,导致报错。
全栈程序员站长
2022/08/24
6580
MySQL5.7版本sql_mode=only_full_group_by问题解决办法
使用GROUP BY 发生错误 SELECT list is not in GROUP BY clause .......... 解决
Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.w.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
友儿
2022/09/11
2.2K0
MySQL学习,详解分组查询(二)
where & group by & having & order by & limit ⼀起协作
用户1289394
2021/10/26
1.9K0
mysql 版本bug
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
超蛋lhy
2018/08/31
1.5K0
解决 mysql8 报错 this is incompatible with sql_mode = only_full_group_by
报错内容 Error Code: 1055. Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column '{field}' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by 0.053 sec 确认
崔哥
2022/05/25
6150
MySQL5.7之group by语法问题
使用group by 进行分组查询时,提示异常: SELECT list is not in GROUP BY clause and contains nonaggregated column ‘XXX’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode =only_full_group_by
执笔记忆的空白
2020/12/24
9060
MySQL遇见SELECT list is not in GROUP BY clause and contains nonaggre的问题
方法一 使用命令行或者数据库客户端执行SQL 1.SQL语句,select @@global.sql_mode查询
流柯
2020/08/28
2.5K0
MySQL使用group by分组时报错
第一项默认开启ONLY_FULL_GROUP_BY了,导致出现了错误,需要把它的默认关掉。
Autooooooo
2020/11/09
1.8K0
MySQL使用group by分组时报错
MySQL 排错-解决MySQL非聚合列未包含在GROUP BY子句报错问题
SELECT id, name, count(*) AS cnt FROM case_table GROUP BY name
授客
2019/09/29
1.8K0
【黄啊码】MySQL:Syntax error or access violation: 1055 Expression #1 of SELECT list is not ...
错误原因: MySQL 5.7.5及以上版本实现了对功能依赖的检测。如果启用了only_full_group_by SQL模式(在默认情况下是这样),那么MySQL就会拒绝选择列表、条件或顺序列表引用的查询,这些查询将引用组中未命名的非聚合列,而不是在功能上依赖于它们。(在5.7.5之前,MySQL没有检测到功能依赖项,only_full_group_by在默认情况下是不启用的。关于前5.7.5行为的描述,请参阅MySQL 5.6参考手册。)
黄啊码
2022/01/09
5720
MySQL5.7 中使用 group by 报错 this is incompatible with sql_mode=only_full_group_by
这个错误发生在mysql 5.7 版本及以上版本,5.7版本默认的sql_mode配置中包含 ONLY_FULL_GROUP_BY,这个配置严格执行了”SQL92标准”
很酷的站长
2023/01/02
2.4K1
MySQL5.7 中使用 group by 报错 this is incompatible with sql_mode=only_full_group_by
MySQL 报错:5.7版本sql_mode=only_full_group_by问题
MySQL 5.7.9版本sql_mode=only_full_group_by问题 用到GROUP BY 语句查询时com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘col_user_6.a.START_TIME’ which is not functional
学到老
2018/03/19
1.4K0
MySQL多列字段去重的案例实践
提起"唯一值",想到的就是distinct。distinct关键字可以过滤多余的重复记录只保留一条。
爱可生开源社区
2023/05/11
3.2K0
MySQL多列字段去重的案例实践
解决SQL中的“Expression #1 of SELECT list is not in GROUP BY clause“错误
大家好,默语:Java高级工程师、自媒体博主,北京城市开发者社区的主理人。喜欢记录工作中的技术心得,创作文章,全网10余万粉丝,总阅读量超过700万。活跃于CSDN、掘金、阿里云和51CTO等平台,是CSDN博客专家、阿里云专家博主和掘金博客专家,曾获博客专家、优秀社区主理人等多项荣誉,并在2023年度博客之星评选中名列前50。目前就职于国企并担任技术经理,拥有丰富的项目开发经验和产品设计能力。希望在不断的学习过程中,可以帮助到更多的人,结交更多的朋友。
默 语
2024/11/22
4760
推荐阅读
相关推荐
mysql5.7 group by语法 1055
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档