执行语句: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;
# 更改sql_mode
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
更改设置之后,问题解决。
参考博客:
https://cloud.tencent.com/developer/article/1404739