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

Re: sql

From: "Andrei Bintintan" <klodoma(at)ar-sd(dot)net>
To: "cristivoinicaru" <cristivoinicaru(at)dmhi(dot)ct(dot)ro>,<pgsql-sql(at)postgresql(dot)org>
Subject: Re: sql
Date: 2004-10-25 10:04:46
Message-ID: 003001c4ba7a$0fbb3500$0b00a8c0@forge (view raw or flat)
Thread:
Lists: pgsql-sql
> 2)if two ore more record have the same value of the maxim value of the
"ora"
> to select oly one of them

At this point you really have to decide which criteria you use for this
deciding.

I strongly suggest to use a uniqe ID for each row in the table(in your case
it is important):
CREATE TABLE "temp50" (
id serial primary key,
  "gc" character varying(36),
  "co" character varying(7),
  "data" date,
  "ora" smallint
 );

Your selection can be made in many ways, but you have to decide the second
criteria.

One more thing:
Your table datas are:
1 >> 5003707G9G9419 22012BB 10-14-2004 82
2 >> 5003707G9G9419 22012BC 10-14-2004 44
3 >> 5003707G9G9419 22022BB 10-14-2004 82
4 >> 5003707G9G9420 22022BC 10-18-2004 49

The rows no 1 and 3 are "redundant" data's(they are the same). Do you really
want this???

Best regards,
Andy.

----- Original Message -----
From: "cristivoinicaru" <cristivoinicaru(at)dmhi(dot)ct(dot)ro>
To: <pgsql-sql(at)postgresql(dot)org>
Sent: Monday, October 25, 2004 11:13 AM
Subject: [SQL] 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!
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
>



In response to

  • sql at 2004-10-25 08:13:37 from cristivoinicaru

pgsql-sql by date

Next:From: James CloosDate: 2004-10-25 10:36:38
Subject: Re: bibliographic schema
Previous:From: JNDate: 2004-10-25 09:27:01
Subject: Re: now() + integer, not rounded to whole day

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