Q:

Calculate the leave net entitlement difference between two days

There are two queries i am fetching one which gives todays absence balance 
and another which will will give yesterdays absence balance 
Todays Net entitlement :
query 1 :

select e.emp_no,
a.absence_code,
a.net_entitlement
from emp_details e,
absence_tab_history a
where a.person_id=e.person_id
and a.history_date=trunc(sysdate);

Yesterday's net entitlemet :
query 2 :

select e.emp_no,
a.absence_code,
a.net_entitlement
from emp_details e,
absence_tab_history a
where a.person_id=e.person_id
and a.history_date=trunc(sysdate)-1;

now query 1 will fetch columns for todays net entitlement such as 
emp no. Absence code        net entitlement

1        Sick Leave             9
2        Privilege Leave        5
3        Sick Leave             5

now query 2 will fetch columns for yesterdays  net entiltement of employees
emp no. Absence code        net entitlement

1        Sick Leave             10
2        Privilege Leave        5
3        Sick Leave             6

This means that emp no. 1 and 2's net entitlement have changed and both of them have taken 1 leave  each. Now i want to create a query which captures the same ie. only emp 1 and 2 
That is if teh net entitlement has changed  then displays the changed rows only.
Minus is not working for this and is taking too much time to execute. Kindly help

A:

    with present_day 
as
(
select 1 as emp_id,'Sick Leave' as code , 9 as net_entitlement from dual
union
select 2 as emp_id,'Privilege Leave' as code , 5 as net_entitlement from dual
union
select 3 as emp_id,'Sick Leave' as code , 5 as net_entitlement from dual
),
yester_day
as
(
select 1 as emp_id,'Sick Leave' as code , 10 as net_entitlement from dual
union
select 2 as emp_id,'Privilege Leave' as code , 5 as net_entitlement from dual
union
select 3 as emp_id,'Sick Leave' as code , 6 as net_entitlement from dual
)

select a.emp_id,a.code,a.net_entitlement,decode(a.net_entitlement-b.net_entitlement,0,'UNCHG','CHNG')
from present_day a,yester_day b
where a.emp_id=b.emp_id and a.code=b.code
and decode(a.net_entitlement-b.net_entitlement,0,'UNCHG','CHNG')='CHNG'

Try the above code and let me know

