项目由开发环境 提测到 测试环境,报如下错误:
[Err] 1055 - Expression #1 of ORDER BY clause is not
in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ'
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版本中默认是开启sql_mode = only_full_group_by
。
而在这个模式下,我们使用分组查询时,出现在select字段后面的只能是group by后面的分组字段,或使用聚合函数包裹着的字段。
解决方法:去掉 only_full_group_by
// 查询有哪些模式
select @@global.sql_mode;
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`;