SELECT d.dept_no,de.dept_name,count(*) sum FROM salaries s LEFT JOIN dept_emp d ON s.emp_no=d.emp_no LEFT JOIN departments de ON d.dept_no=de.dept_no GROUP BY dept_no ORDER BY dept_no两次左外连接把三个表连成一个,然后分组计数