Re: [SQL] For each record in SELECT

From: "Andrew J(dot) Kopciuch" <akopciuch(at)bddf(dot)ca>
To: joe666(at)gnovus(dot)com, PostgreSQL General <pgsql-general(at)postgresql(dot)org>, PostgreSQL Novice <pgsql-novice(at)postgresql(dot)org>, PostgreSQL SQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: [SQL] For each record in SELECT
Date: 2003-02-01 02:36:17
Message-ID: 200301311936.18611.akopciuch@bddf.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-novice pgsql-sql

On Friday 31 January 2003 14:21, Luis Magaña wrote:
> Hi,
>
> I have a question here:
>
> I have a table with this fields:
>
> month
> description
> amount
>
> now I have to write a query that retrieves the sum of the amount from
> the minimum month to the maximum month registered for each diferent
> description.
>

From what I understand in your email you just need to add a GROUP BY clause.
Try a query like this.

SELECT description, sum(amount) FROM table GROUP BY description;

That should do what you need,

Andy

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michelle Konzack 2003-02-01 04:17:16 Re: passwords and 7.3
Previous Message Keary Suska 2003-02-01 01:49:44 Re: SQL-question (JOIN)

Browse pgsql-novice by date

  From Date Subject
Next Message Michelle Konzack 2003-02-01 03:28:40 Re: Postgresql with OOo
Previous Message Keary Suska 2003-02-01 01:28:34 Re: For each record in SELECT

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2003-02-01 04:09:31 Re: Controlling access to Sequences
Previous Message Guy Fraser 2003-02-01 01:32:08 Re: CSV import