Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Interesting data transposition problem

Interesting data transposition problem

From: <puneet.bansal_at_wipro.com>
Date: 9 Jun 2005 15:25:23 -0700
Message-ID: <1118355923.142832.214000@g14g2000cwa.googlegroups.com>


Hi,

I am handling a complex query and ultimately the problem boils down to this.
I have the data in the format

Col1      Col2
X          a
X          b
Y          c
Y          d
Y          e

but I need this data in the following format (note that the column names have changed to the data)

X         Y
a         c
b         d
          e

I have managed to get
X         Y

a
b
          c
          d
          e

but can't get what I want. I am using the following query -

select decode(col1,'X',col2) as x,
decode(col1,'Y',col2) as y
from
(
select 'X' as col1, 'a' as col2 from dual union all
select 'X' as col1, 'b' as col2 from dual union all
select 'Y' as col1, 'c' as col2 from dual union all
select 'Y' as col1, 'd' as col2 from dual union all
select 'Y' as col1, 'e' as col2 from dual )

Can anyone please help?

Thanks.
Puneet Received on Thu Jun 09 2005 - 17:25:23 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US