mysql报错In aggregated query without GROUP BY

执行语句:
select de.dept_no, count(s.salary) from salaries s left join dept_emp de on s.emp_no = de.emp_no;

完整报错信息:
In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'demos.de.dept_no'; this is incompatible with sql_mode=only_full_group_by

经过查找资料,问题是Mysql版本5.7以上会有这个错,更改sql_mode即可。

# 查看sql_mode
select version(), @@sql_mode;

mysql报错In aggregated query without GROUP BY

# 更改sql_mode
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

更改设置之后,问题解决。
mysql报错In aggregated query without GROUP BY

参考博客:
https://cloud.tencent.com/developer/article/1404739

上一篇:一起学HTML基础-利用CSS和JavaScript制作一个切换图片的网页


下一篇:【雕爷学编程】Arduino动手做(75)---TTL转RS-485模块