mysql5.7使用groupby出现1055Expression #2 of SELECT list is not in GROUP BY clause 错误

1、今天想实现一个查看某一个类别的其中一项记录时,使用groupby分组,在mysql5.7出现,如下错误:

Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column

经过一番搜索:在stackflow上找到了答案:https://stackoverflow.com/questions/23921117/disable-only-full-group-by

其中描述一下基本的做法:

第一步:在mysql命令行下执行以下语句:

SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

第二步:在mysql的配置文件中(linux下/etc/my.cnf或者/etc/mysql/my.cnf的[mysqld]下加入以下内容:

[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服务,linux执行sudo service mysql restart

你可能感兴趣的:(mysql,web)