Skip site navigation (1) Skip section navigation (2)

sql

From: "cristivoinicaru" <cristivoinicaru(at)dmhi(dot)ct(dot)ro>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: sql
Date: 2004-10-25 08:13:37
Message-ID: 013901c4ba6a$8771d320$7202a8c0@aaa (view raw or flat)
Thread:
Lists: pgsql-sql
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

Thanks!


Responses

  • Re: sql at 2004-10-25 10:04:46 from Andrei Bintintan
  • Re: sql at 2004-10-25 11:20:22 from Mike Rylander

pgsql-sql by date

Next:From: Muhyiddin A.M HayatDate: 2004-10-25 08:49:51
Subject: Re: Cross tabulations
Previous:From: Larry LennhoffDate: 2004-10-25 03:18:55
Subject: Re: Create interval using column value?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group