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

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 (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-novicepgsql-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

pgsql-novice by date

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

pgsql-general by date

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

pgsql-sql by date

Next:From: Tom LaneDate: 2003-02-01 04:09:31
Subject: Re: Controlling access to Sequences
Previous:From: Guy FraserDate: 2003-02-01 01:32:08
Subject: Re: CSV import

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