Re: sql

From: Jeffrey Melloy <jmelloy(at)visualdistortion(dot)org>
To: cristi <cristi(at)dmhi(dot)ct(dot)ro>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: sql
Date: 2004-06-23 20:38:18
Message-ID: 40D9EA3A.80303@visualdistortion.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

cristi wrote:

>I have the following table structure:
>
>CREATE TABLE "xxx" (
> "co" character varying(7),
> "co1" character varying(9),
> "n1" character varying(15),
> "l1" character varying(5),
> "m1" smallint,
> "ore" bigint
>);
>
>who contains the following date:
>
>22021CC 1044 637 S5G8 407 5
>22021CC 1044 637 S5G8 409 47
>22021CD 1044 637 S5G8 410 24
>22022BB 1044 637 S5G8 409 10
>
>I need a SQL select which result to be:
>
>22021CC 1044 637 S5G8 407 5
>22021CC 1044 637 S5G8 409 57
>22021CD 1044 637 S5G8 410 24
>
>I mean:
>I want to select the records wich for co1,n1,l1,m1 value are the same and
>has the maxim value of the ore field
>adding to that value the value of the records which are not selected.
>
>Wou!
>Thanks in advance!
>
>

What you want is an aggregate. Saying "adding to that value the value
of the records which are not selected" is kind of a weird way to say it,
though.

select co, co1, n1, l1, m1, sum(ore)
from xxx
where [...]
group by co, co1, n1, l1, m1

Should get you exactly what you need.

In response to

  • sql at 2004-06-23 10:26:42 from cristi

Responses

  • Re: sql at 2004-06-24 18:20:43 from Manfred Koizar

Browse pgsql-novice by date

  From Date Subject
Next Message Frank Kurzawa 2004-06-23 22:28:45 Re: Committed updates don't seem to be committed.
Previous Message Tom Lane 2004-06-23 19:33:25 Re: pgHoster.com woes and looking for a new host