当前位置:   article > 正文

mysql5.7使用groupby出现1055Expression #2 of SELECT list is not in GROUP BY clause 错误_42000][1055] expression #2 of select list is not i

42000][1055] expression #2 of select list is not in group by clause and

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

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

在mysql中使用select @@sql_mode;查询:可以看到有ONLY_FULL_GROUP_BY

  1. select @@sql_mode;
  2. 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命令行下执行以下语句: 

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

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

  1. [mysqld]
  2. 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服务

[root@hadoop01 mysql-5.7]# systemctl restart mysqld.service

再次查询

  1. select @@sql_mode;
  2. STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/899557
推荐阅读
相关标签
  

闽ICP备14008679号