mysql查询报错: ORDER BY clause is not in GROUP BY..this is incompatible with sql_mode=only_full_group_by
在用mysql执行如下查询的时候:
select * from fruits GROUP BY s_id,f_name;
- 1
报错信息如下:
[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
- 1
错误的原因是我mysql版本是5.7的,使用如下语句查询可知
select @@sql_mode;
- 1
里面默认设置了
sql_mode=only_full_group_by
- 1
only_full_group_by
:使用这个就是使用和oracle一样的group 规则, select的列都要在group中,或者本身是聚合列(SUM,AVG,MAX,MIN) 才行,其实这个配置目前个人感觉和distinct差不多的,所以去掉就好
在windows系统里面,直接修改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
- 1
到此mysql配置文件的完整配置如下: