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

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Inserting data from long table into wide table

Re: Inserting data from long table into wide table

From: Erma Fernando <cecfernan_at_hotmail.com>
Date: Thu, 22 Mar 2001 13:47:36 -0800
Message-ID: <F001.002D559F.20010322132209@fatcity.com>

Thanks Regina. It works!
Erma
>From: Regina Harter <rharter_at_emc-inc.com>
>Reply-To: ORACLE-L_at_fatcity.com
>To: Multiple recipients of list ORACLE-L <ORACLE-L_at_fatcity.com>
>Subject: Re: Inserting data from long table into wide table
>Date: Thu, 22 Mar 2001 11:56:30 -0800
>
>I believe a decode and group by would work well for you, something like:
>
>insert into tableb
>select id, sum(decode(name,'P1',value,0)), sum(decode(name,'P2',value,0)),
>...
>from tablea group by id;
>
>At 11:19 AM 3/22/01 -0800, you wrote:
>>I have a table A with the following data (Table A has 3 columns id, name,
>>value)
>>
>>id name value
>>10 P1 20
>>10 P2 60
>>10 P3 12.5
>>10 P4 26
>>20 P1 100
>>20 P2 90
>>20 P3 15
>>20 P4 36
>>30 P1 60
>>30 P2 50
>>30 P3 11.5
>>30 P4 13
>>.... more rows
>>
>>I want to insert this data into table B as follows (Table B has 4 columns
>>id, P1, P2, P3, P4)
>>
>>
>>id P1 P2 P3 P4
>>10 20 60 12.5 26
>>20 100 90 15 36
>>30 60 50 11.5 13
>>... more rows
>>
>>Can you suggest a Sql statement for the insert into table B. Thank you
>>very much in advance.
>>Erma
>>_________________________________________________________________________
>>Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
>>
>>--
>>Please see the official ORACLE-L FAQ: http://www.orafaq.com
>>--
>>Author: Erma Fernando
>> INET: cecfernan_at_hotmail.com
>>
>>Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
>>San Diego, California -- Public Internet access / Mailing Lists
>>--------------------------------------------------------------------
>>To REMOVE yourself from this mailing list, send an E-Mail message
>>to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
>>the message BODY, include a line containing: UNSUB ORACLE-L
>>(or the name of mailing list you want to be removed from). You may
>>also send the HELP command for other information (like subscribing).
>
>--
>Please see the official ORACLE-L FAQ: http://www.orafaq.com
>--
>Author: Regina Harter
> INET: rharter_at_emc-inc.com
>
>Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
>San Diego, California -- Public Internet access / Mailing Lists
>--------------------------------------------------------------------
>To REMOVE yourself from this mailing list, send an E-Mail message
>to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
>the message BODY, include a line containing: UNSUB ORACLE-L
>(or the name of mailing list you want to be removed from). You may
>also send the HELP command for other information (like subscribing).



Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Erma Fernando
  INET: cecfernan_at_hotmail.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Thu Mar 22 2001 - 15:47:36 CST

Original text of this message

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