select dp.dept_no dept_no,dp.dept_name dept_name,count(ds.salary) sum
from departments dp 
join 
(select salary,de.dept_no
from dept_emp de join salaries sa on de.emp_no=sa.emp_no) ds
on 
dp.dept_no=ds.dept_no
group by dp.dept_no
order by dp.dept_no