Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.emplo

情况:输入以下命令
select group_concat(name),salary from employee left join department on employee.departmentID=department.d_id group by department.d_id;

mysql里一旦报这个错:select group_concat(name),salary from employee left join department on employee.departmentID=department.d_id group by department.d_id;,要第一反应是group by 出问题了,原因是 分组后你的salary等字段的内容不止一个,所以无法分组。

解决办法:给salary等字段也加上group_concat(),让多个字段可以在同一组下显示。
select group_concat(name),group_concat(salary) from employee left join department on employee.departmentID=department.d_id group by department.d_id;

你可能感兴趣的:(报错)