dkbailey1
asked on
Oracle SQL statement needed to align column values across the record
I have a resultset like the following:
Name Type Hours
--------------- ---------- -------------
John Direct 10
Jane Indirect 20
Mary Direct 15
That I need to look like this:
Name Direct Indirect
------------- ------------- ------------
John 10 0
Jane 0 20
Mary 15 0
I think this is possible can somebody provide the Oracle SQL?
Thanks.
Name Type Hours
--------------- ---------- -------------
John Direct 10
Jane Indirect 20
Mary Direct 15
That I need to look like this:
Name Direct Indirect
------------- ------------- ------------
John 10 0
Jane 0 20
Mary 15 0
I think this is possible can somebody provide the Oracle SQL?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try this, (x is thetable)
select tab1.name, NVL(tab2.hours,0) DIRECT,
NVL(tab3.hours,0) INDIRECT
from x tab1,
x tab2,
x tab3
where tab1.name = tab2.name (+)
and tab1.name = tab3.name (+)
and tab2.type (+) = 'DIRECT'
and tab3.type (+) = 'INDIRECT'
select tab1.name, NVL(tab2.hours,0) DIRECT,
NVL(tab3.hours,0) INDIRECT
from x tab1,
x tab2,
x tab3
where tab1.name = tab2.name (+)
and tab1.name = tab3.name (+)
and tab2.type (+) = 'DIRECT'
and tab3.type (+) = 'INDIRECT'
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry I forgot: I would not prefer the self outer join solution, Why adding overhead with joins etc?
Yes while there is a solution without join that is better
select
name,
decode(Type,'Direct',Hours
decode(Type,'Indirect',Hou
from
thetable