this is incompatible with sql_mode=only_full_group_by

报错信息:

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'xxxx' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

原因:

这是因为mysql5.7及以上版本的mysql中,对于 group by 的这种聚合操作,如果在select 中的列,

没有在group by 中出现,那么这个SQL是不合法的,因为列不在group by的从句中,所以对于设置了这个mode的数据库,在使用group by 的时候,就要用MAX(),SUM(),ANT_VALUE()的这种聚合函数,才能完成GROUP BY 的聚合操作。

解决方法:

1、首先查询你的数据库是否包含:only_full_group_by

select @@global.sql_mode

2、如果包含接着下面的步骤,修改my.cnf

vim my.cnf

找到sql_mode 去掉only_full_group_by

如果没有sql_mode 追加如下代码:

sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

3、重启mysql

systemctl restart mysqld

相关推荐
夜泉_ly2 小时前
MySQL -安装与初识
数据库·mysql
qq_529835353 小时前
对计算机中缓存的理解和使用Redis作为缓存
数据库·redis·缓存
月光水岸New5 小时前
Ubuntu 中建的mysql数据库使用Navicat for MySQL连接不上
数据库·mysql·ubuntu
狄加山6755 小时前
数据库基础1
数据库
我爱松子鱼5 小时前
mysql之规则优化器RBO
数据库·mysql
chengooooooo6 小时前
苍穹外卖day8 地址上传 用户下单 订单支付
java·服务器·数据库
Rverdoser7 小时前
【SQL】多表查询案例
数据库·sql
Galeoto7 小时前
how to export a table in sqlite, and import into another
数据库·sqlite
人间打气筒(Ada)7 小时前
MySQL主从架构
服务器·数据库·mysql
leegong231117 小时前
学习PostgreSQL专家认证
数据库·学习·postgresql