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