当前位置: > 数据库 > MySQL >

mysql5.7后用group by 查询时抛出异常

时间:2019-05-05 17:58来源:linux.it.net.cn 作者:IT
      MySQL 5.7.5后实现了对功能依赖的检测。默认启用了only_full_group_by 的SQL模式,会抛出:Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'userinfo.

      在session和global 的sql_mode的值都为:


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
 执行select @@sql_mode;查询;执行以下两个命令去掉:ONLY_FULL_GROUP_BY就好;

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


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




(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容