SELECT D.dept_no, D.dept_name, COUNT(S.salary) AS sum FROM salaries AS S LEFT JOIN dept_emp AS DE ON DE.emp_no = S.emp_no LEFT JOIN departments AS D ON D.dept_no = DE.dept_no GROUP BY D.dept_no ORDER BY D.dept_no
SELECT D.dept_no, D.dept_name, COUNT(S.salary) AS sum FROM salaries AS S LEFT JOIN dept_emp AS DE ON DE.emp_no = S.emp_no LEFT JOIN departments AS D ON D.dept_no = DE.dept_no GROUP BY D.dept_no ORDER BY D.dept_no