From: | Mike Rylander <mrylander(at)gmail(dot)com> |
---|---|
To: | cristivoinicaru <cristivoinicaru(at)dmhi(dot)ct(dot)ro> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: sql |
Date: | 2004-10-25 11:20:22 |
Message-ID: | b918cf3d041025042021ca123e@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Mon, 25 Oct 2004 10:13:37 +0200, cristivoinicaru
<cristivoinicaru(at)dmhi(dot)ct(dot)ro> wrote:
> I have a postgres table like this:
>
> CREATE TABLE "temp50" (
> "gc" character varying(36),
> "co" character varying(7),
> "data" date,
> "ora" smallint
>
> );
>
> It contains the following records:
>
> 5003707G9G9419 22012BB 10-14-2004 82
> 5003707G9G9419 22012BC 10-14-2004 44
> 5003707G9G9419 22022BB 10-14-2004 82
> 5003707G9G9420 22022BC 10-18-2004 49
>
> I'd like the result of the sql interogation to be like this:
>
> 5003707G9G9419 22012BB 10-14-2004 82
> 5003707G9G9420 22022BC 10-18-2004 49
>
> Explanations:
> I want like sql interogation to select only one record from each "gc" group
> record (who has the same code "gc" (that means that the "gc" field will be
> unique key)) with the following two condition:
> 1)from each "gc" group of records to select the record who has the value of
> "ora" field maxim.
> 2)if two ore more record have the same value of the maxim value of the "ora"
> to select oly one of them
Try:
SELECT * FROM temp50 GROUP BY gc ORDER BY ora DESC;
--miker
>
> Thanks!
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
>
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew J. Kopciuch | 2004-10-25 11:44:06 | Re: sql |
Previous Message | James Cloos | 2004-10-25 10:36:38 | Re: bibliographic schema |