If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > convert the rows of data into columns in db2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-30-09, 02:51
adu_143 adu_143 is offline
Registered User
 
Join Date: Feb 2009
Posts: 2
convert the rows of data into columns in db2

Hi,

In db2 I want to write a sql that can take the values from a table which has multiple rows in it and want to consolidate them to another table with multiple columns.

for example the table data from table A is as follows

column contract column value
1-A 25
1-A 50
1-A 75
1-B 15
1-B 20
...

then the table b should look like as follows -

col1 col2 col3 col4
1-A 25 50 75
1-B 15 20 -
.....


how do I do this in db2?
Reply With Quote
  #2 (permalink)  
Old 04-30-09, 02:59
rahul_s80 rahul_s80 is offline
Registered User
 
Join Date: Jul 2006
Location: Pune , India
Posts: 433
google :
db2 pivot unpivot table
__________________
Rahul Singh
Certified DB2 9 DBA / Application Developer
Reply With Quote
  #3 (permalink)  
Old 04-30-09, 03:02
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Or search this forum with "recursive query".
Reply With Quote
  #4 (permalink)  
Old 04-30-09, 05:25
adu_143 adu_143 is offline
Registered User
 
Join Date: Feb 2009
Posts: 2
Quote:
Originally Posted by rahul_s80
google :
db2 pivot unpivot table

Can you please help me with the desired query .. I looked for the example given on one of the site, but that has 3 cols and based on value of 2nd col he is picking up value of third.
In my case , I only have two cols as given ...
Reply With Quote
  #5 (permalink)  
Old 04-30-09, 12:07
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Quote:
... but that has 3 cols and based on value of 2nd col he is picking up value of third.
In my case , I only have two cols as given ...
You can pick up value of 2nd col based on value of 2nd col.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On