知识点

  1. 不写order by通过不了测试,但是应该默认是部门升序排序这边不太清楚原因
  2. 将三张表连接起来,按照部门再按照title进行排序
  3. 数目就是用count计数

代码

select b1.dept_no, b1.dept_name, t.title, count(t.title ) as count
from titles as t 
join (select d.dept_no,d.dept_name,de.emp_no
    from departments as d 
    join dept_emp as de
    on d.dept_no = de.dept_no
) as b1
on t.emp_no = b1.emp_no
group by b1.dept_no, t.title
order by b1.dept_no