For each record in SELECT

From: Luis Magaña <joe666(at)gnovus(dot)com>
To: 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: For each record in SELECT
Date: 2003-01-31 21:21:17
Message-ID: 1044048077.1380.3.camel@kerberus
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-novice pgsql-sql

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.

Of course there are cases when a particular description has not record
for all the months in that period. I mean, suppouse you have this
records:

month description amount
-----------------------------------------------
June description1 100
July description1 500
August description1 600
June description2 300
August description2 400

how you write a query that outputs something like this:

June July August
------------------------------------------
description1 | 100 500 600
description2 | 300 0 400

My problem is for the 0 value.

I hope I've explained clearly my question.

Thanks for the help.

Best Regards.

--
Luis Magaña.
Gnovus Networks & Software.
www.gnovus.com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Robert Treat 2003-01-31 21:29:40 Re: using pgcrypt
Previous Message pilsl 2003-01-31 21:20:52 SQL-question (JOIN)

Browse pgsql-novice by date

  From Date Subject
Next Message Oliver Elphick 2003-01-31 22:01:47 Re: where is libpq.so
Previous Message Robert Mosher 2003-01-31 20:04:36 serial field starting at specific value

Browse pgsql-sql by date

  From Date Subject
Next Message Keary Suska 2003-02-01 01:28:34 Re: For each record in SELECT
Previous Message Joe Conway 2003-01-31 19:32:59 Re: Postgres MD5 Function