MySQL执行多表联查时,报错ln aggregated query without GROUP BY

问题:mysql5.7,执行sql语句报错:In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregated column 'department_id'; this is incompatible with sql_mode=only_full_group_by

解决办法:

①通过navicat,新建查询窗口,输入select @@global.sql_mode来查看当前数据库的sql_mode属性值

MySQL执行多表联查时,报错ln aggregated query without GROUP BY

②复制上面截图查询结果,重新赋值时,去掉ONLY_FULL_GROUP_BY,执行成功后,就可以将ONLY_FULL_GROUP_BY模式默认设置为关闭状态:

MySQL执行多表联查时,报错ln aggregated query without GROUP BY

③查询是否关闭,执行①步骤语句,发现已关闭ONLY_FULL_GROUP_BY模式,关闭连接再重新连接即可执行之前报错的语句。

MySQL执行多表联查时,报错ln aggregated query without GROUP BY

更多解决办法参考该博客:https://blog.****.net/Peacock__/article/details/78923479