下面是employee表的所有数据。
MySQL使用group by 报this is incompatible with sql_mod_第1张图片
使用group by 分组查询报错this is incompatible with sql_mode=only_full_group_by
MySQL使用group by 报this is incompatible with sql_mod
查看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

MySQL使用group by 报this is incompatible with sql_mod

ONLY_FULL_GROUP_BY选项开启,那么在使用group by时候, 只能select查询group by后面的选项,或者使用聚合函数。
只查询group by后面的列:
MySQL使用group by 报this is incompatible with sql_mod_第2张图片
使用聚合函数:
MySQL使用group by 报this is incompatible with sql_mod_第3张图片
但以上两种方法不推荐!!!
推荐解决方法:
1.临时,重启mysql会失效
MySQL使用group by 报this is incompatible with sql_mod
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_第4张图片