题解 | #统计各个部门的工资记录数#
统计各个部门的工资记录数
http://www.nowcoder.com/practice/6a62b6c0a7324350a6d9959fa7c21db3
select de.dept_no,de.dept_name,
(select count(*) from salaries s2 where s2.emp_no in
(select emp_no from dept_emp d2 where d2.dept_no = d1.dept_no))
from dept_emp d1 join departments de using(dept_no) group by dept_no
order by d1.dept_no;
通过d2.dept_no = d1.dept_no 查找出每个部门的所有员工id s2.emp_no in 查询到每个员工id对应的记录数,然后 count(*)