SELECT de.dept_no, d.dept_name, t.title, count(t.emp_no)
FROM
dept_emp AS de 
JOIN departments AS d
ON de.dept_no = d.dept_no
JOIN titles AS t
ON de.emp_no=t.emp_no
WHERE de.to_date = '9999-01-01'
AND t.to_date = '9999-01-01'
GROUP BY dept_no,dept_name,title
ORDER BY d.dept_no, t.title ASC;