SELECT dept_no, GROUP_CONCAT(emp_no)
FROM dept_emp
GROUP BY dept_no;

mysql有三种拼接方法:

concat('str1', ',', 'str2')

concat_ws('需要使用的分隔符', 'str1', 'str2',···)

group_concat('分组后想要拼接的字段' Separator '想要使用的分隔符')

其中第三中方法可以不用添加Separator '想要使用的分隔符',默认为','。