DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: Transpose rows into columns

  1. #1
    Join Date
    Dec 2000
    Posts
    138

    Transpose rows into columns

    I have some data in a table with data in rows and would like to transform them to rows.

    the data is like this

    id no val
    ----------
    01 10 123
    01 20 100
    01 30 234
    02 10 125
    02 20 345

    and should be transformed into (and inserted into a table)

    id |10 | 20 | 30
    ---------------------
    01 |123| 100| 234
    02 |125| 345| 0


    is there any way to do that other than a

    select a.id,a.no,a.val,b.val,c.val
    from
    (select id,no,val from table
    where no=10) a,
    (select id,no,val from table
    where no=20) b,
    (select id,no,val from table
    where no=30) c
    where a.id=b.id
    and a.id=c.id

    (also note that I may need something of a FULL OUTER JOIN)
    DB Version : 9i rel 2

    Any help is appreciated.
    Thanks,
    -dharma
    Last edited by dharma; 06-05-2003 at 12:25 PM.

  2. #2
    Join Date
    Dec 2000
    Posts
    138
    mmm..a small push isnt a bad idea

    PS: apoplogies though.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width