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: A SQL question, please help...

Re: A SQL question, please help...

From: Jurij Modic <jmodic_at_src.si>
Date: 1998/11/24
Message-ID: <365b3d5b.4406348@news.arnes.si>#1/1

On Wed, 25 Nov 1998 02:18:57 -0800, Jimmy <c6635500_at_comp.polyu.edu.hk> wrote:

>Hello all,
>
> I have the following rows in table A:
>...[SNIP]...
> Field value is the same with the same date. The table, in fact, has
>problem of splitting the same date row into different rows. So I want to
>combine the same date row as the following table:
>
> ID date A1 A2 A3
> 1 01-Jan-98 10 11 12
> 4 01-Feb-98 20 21 22
>
> i.e. combine the rows with the same date, use the smallest ID among the
>same date rows. The field value may be character.
>
> Can I do that by using SQL statement?

If the column values for the same date are realy allways unique (or null) then it is quite simple:

SELECT MIN(id), date_col, MAX(a1), MAX(a2), MAX(a3) FROM your_table GROUP BY date_col;

You can use some other group function instead of MAX, for example AVG or MIN should behave exactly the same.

>Thanks,
>Jimmy

HTH, Jurij Modic <jmodic_at_src.si>
Certified Oracle7 DBA (OCP)



The above opinions are mine and do not represent any official standpoints of my employer Received on Tue Nov 24 1998 - 00:00:00 CST

Original text of this message

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