Mysql 分组查询问题 SELECT list is not in GROUP BY clause which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

一.问题描述  

ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause 
and contains nonaggregated column 'player.song_sheet.type' which is not 
functionally dependent on columns  in GROUP BY clause; this is 
incompatible with sql_mode=only_full_group_by

二. 解决方法1

1.查询mysql 相关mode

select @@global.sql_mode;

可以看到模式中包含了ONLY_FULL_GROUP_BY,只要没有这个配置即可。

我的Mysql版本是5.7.23,默认是带了ONLY_FULL_GROUP_BY模式。 

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

2.重置改模式

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';

  

三.解决方法二

1.打开mysql配置文件:my.cnf,或my.ini,然后在[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即可

posted @ 2019-09-21 18:08  逗码农  阅读(163)  评论(0)    收藏  举报