三表连接, 然后按部门号,部门名, title类型分组, 最后按部门号排序

select d.dept_no, d.dept_name, t.title, count(t.title)
from departments d 
join dept_emp e 
on d.dept_no=e.dept_no
join titles t 
on e.emp_no = t.emp_no
where e.to_date = '9999-01-01' and t.to_date='9999-01-01'
group by d.dept_no, d.dept_name, t.title
order by d.dept_no;