题解 | #统计各个部门的工资记录数#
统计各个部门的工资记录数
http://www.nowcoder.com/questionTerminal/6a62b6c0a7324350a6d9959fa7c21db3
/*
子查询结果建立新表 t1:
1001 d001 (分组聚合后) d001 3
1001 d001 - - - - - - ->
1002 d001 d002 1
1003 d002
/
select d.,t1.sumNumbers
from departments as d
left join (
select d_e.dept_no,count(*) as sumNumbers
from salaries as s left outer join dept_emp as d_e
on s.emp_no = d_e.emp_no
group by d_e.dept_no) as t1
on d.dept_no = t1.dept_no