select
    de.dept_no,
    dp.dept_name dept_name,
    tl.title title,
    count(tl.title) count
from
    dept_emp de
    join titles tl on de.emp_no = tl.emp_no
    left join departments dp on de.dept_no = dp.dept_no
where
    de.to_date = '9999-01-01'
group by
    de.dept_no,
    tl.title
order by
    de.dept_no,
    tl.title