mysql 报错 incompatible with only_full_group_by

来源:互联网 发布:怎么使用淘宝客推广 编辑:程序博客网 时间:2024/05/20 23:56

mysql报错:

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

mysql 版本: 5.7.x
修复办法:

sudo vim /etc/my.cnf #(根据实际修改配置文件)#添加下面的配置:[mysql]sql_mode=IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTIONsudo service mysql restart

或者每次查询之前,先运行 sql:

set SESSION sql_mode='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 意味着你只能 select group by 的那个字段 或者使用 MIN() MAX() 等聚合的其它字段

当然你也可以规范你的 sql查询语句,保持默认配置。

阅读全文
1 0
原创粉丝点击