考虑到有员工没职称是很正常的事,对空值小小的做了下区分 select de.dept_no,de.dept_name,if(t.title is null,'nothing',t.title),count(t.title) 人数 from departments de join dept_emp dp on de.dept_no=dp.dept_no left join titles t on dp.emp_no=t.emp_no where dp.to_date='9999-01-01' and t.to_date='9999-01-01' group by de.dept_no,t.title order by de.dept_no,t.title