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 -> Re: merging rows

Re: merging rows

From: Noel <tbal_at_go2.pll-l>
Date: Wed, 20 Apr 2005 10:55:02 +0200
Message-ID: <d455f5$m3r$1@inews.gazeta.pl>


Użytkownik vissuyk_at_yahoo.com napisał:
> Hi All,
>
> What is the best way to merge some rows. Lets say I have three rows in
> a table and I want to replace them three with one row.
>
> Columns: A, B , C, D , E
>
> If Columns A, B and C are equal for rows then I want to merge those
> rows into one. I would use SUM on D and AVG on E.

There is no single SQL command to merge rows.

1. Do a copy of that table.
2. Truncate this table.
3. Fill that table from copy:

  INSERT INTO <TABLE>(A,B,C,D,E)
   SELECT A, B, C, SUM(D), AVG(E)
     FROM <TABLE_COPY>
    GROUP BY A,B,C; and commit changes.

-- 
Noel
Received on Wed Apr 20 2005 - 03:55:02 CDT

Original text of this message

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