by using join and as you stated last two month that why i use now()
and month
function and if month column contain month number
select t1.emp_id,t1.name,(t1.salary-t2.salary) as sal_diff from
(
select *
from a_test
where month=Month(now())
) as t1
left join
(
select * from a_test
where month=month(now())-1
) as t2
on t1.emp_id=t2.emp_id
but if you use month name then use MONTHNAME
in your month column then query will be
select t1.emp_id,t1.name,(t1.salary-t2.salary) as sal_diff from
(
select *
from a_test
where month=MONTHNAME(STR_TO_DATE(month(now()), '%m'))
) as t1
left join
(
select * from a_test
where month=MONTHNAME(STR_TO_DATE(month(now())-1, '%m'))
) as t2
on t1.emp_id=t2.emp_id