select department
,avg(act_salary) avg_salary
from 
(
	select staff_id
	,round(normal_salary - dock_salary,3) act_salary
	from salary_tb
	where round(normal_salary - dock_salary,3) between 4000 and 30000
) salary 
join staff_tb
on salary.staff_id = staff_tb.staff_id
group by 1
order by avg_salary desc