mysql数据库5.5与5.7之间,group by的变化,在某些情景下,无法order by 后执行 group by会有很大影响。
通过explain可以清晰看出
order by是直接省略没有执行的一步。
5.5和5.7代码的运行会导出不同的结果。
需要对order by 进行限制,强制执行
通过对order by 的限制,可以看到这次的order by有执行过程
除了使用limit限制外,也可以在不使用group by 的字段上使用any_value()函数。
mysql命令gruop by报错this is incompatible with sql_mode=only_full_group_by
在mysql 工具 搜索或者插入数据时报下面错误:
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'database_tl.emp.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
原因:
看一下group by的语