select t1.pay_month, t1.department_id,
case when t1.am > t2.am then 'higher' when t1.am < t2.am then 'lower' else 'same' end comparison
from
(
select DATE_FORMAT(pay_date,'%Y-%m') pay_month, department_id , avg(amount) am
from salary s, employee e
where s.employee_id = e.employee_id
GROUP BY pay_month, department_id
) t1,
(
select DATE_FORMAT(pay_date,'%Y-%m') pay_month, avg(amount) am from salary GROUP BY pay_month
) t2
where t1.pay_month = t2.pay_month