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

Re: sql interogation

From: Steven Klassen <sklassen(at)commandprompt(dot)com>
To: cristivoinicaru <cristivoinicaru(at)dmhi(dot)ct(dot)ro>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: sql interogation
Date: 2004-10-25 14:00:40
Message-ID: 20041025140038.GA23440@commandprompt.com (view raw or flat)
Thread:
Lists: pgsql-novice
* cristivoinicaru <cristivoinicaru(at)dmhi(dot)ct(dot)ro> [2004-10-25 10:05:22 +0200]:

> 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 this out; this is from memory, so it hasn't been tested.

SELECT DISTINCT max(gc), co, data, ora FROM temp50 GROUP BY co, data, ora;

-- 
Steven Klassen - Lead Programmer
Command Prompt, Inc. - http://www.commandprompt.com/
PostgreSQL Replication & Support Services, (503) 667-4564

In response to

pgsql-novice by date

Next:From: Tom LaneDate: 2004-10-25 14:06:13
Subject: Re: sql interogation
Previous:From: Pradeepkumar, Pyatalo (IE10)Date: 2004-10-25 09:23:19
Subject: Re: Function to convert bigint to date

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