题解 | #汇总各个部门当前员工的title类型的分配数目#
汇总各个部门当前员工的title类型的分配数目
http://www.nowcoder.com/practice/4bcb6a7d3e39423291d2f7bdbbff87f8
# 部门员工表
select a.dept_no as dept_no
,a.dept_name as dept_name
,b.title as title
,count(b.title) as count_n
from (select de.dept_no,de.dept_name,dem.emp_no
from departments de
join dept_emp dem
on de.dept_no = dem.dept_no)a
join
(select t.emp_no,t.title
from titles t
)b
on a.emp_no = b.emp_no
group by a.dept_no,b.title
order by dept_no,title