MySQL使用group by 报this is incompatible with sql_mod
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL使用group by 报this is incompatible with sql_mod相关的知识,希望对你有一定的参考价值。
下面是employee表的所有数据。
使用group by 分组查询报错this is incompatible with sql_mode=only_full_group_by
查看sql_model参数发现:
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选项开启,那么在使用group by时候, 只能select查询group by后面的选项,或者使用聚合函数。
只查询group by后面的列:
使用聚合函数:
但以上两种方法不推荐!!!
推荐解决方法:
1.临时,重启mysql会失效
set @@GLOBAL.sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
2.修改/etc/my.cnf
[mysqld]
加一行
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
重启MySQL即可生效。
以上是关于MySQL使用group by 报this is incompatible with sql_mod的主要内容,如果未能解决你的问题,请参考以下文章
mysql命令gruop by报错this is incompatible with sql_mode=only_full_group_by
which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mod
windows server 2008 安装MySQL 8.0 遇到报错 1055 - Expression #1 of ORDER BY clause is not in GROUP BY(示例代
mysql5.7 gruop by报错this is incompatible with sql_mode=only_full_group_by
mysql报错this is incompatible with sql_mode=only_full_group_by
Mysql--Cause: java.sql.SQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY