Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: merging rows
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.
-- NoelReceived on Wed Apr 20 2005 - 03:55:02 CDT