From: Keary Suska <hierophant@pcisys.net>
To: PostgreSQL <pgsql-general@postgresql.org>
Subject: Re: For each record in SELECT
Date: Fri, 31 Jan 2003 18:28:34 -0700
Message-ID: <BA6070D1.17EF4%hierophant@pcisys.net> (raw)
In-Reply-To: <1044048077.1380.3.camel@kerberus>
on 1/31/03 2:21 PM, joe666@gnovus.com purportedly said:
> 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.
Getting this kind of result using only a single SQL query is not likely
possible, especially to get the result table you indicate above. In any
case, it would be easier to group by month and description, sum() the
amount, then aggregate the result table in your application.
Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: hierophant@pcisys.net, pgsql-general@postgresql.org
Subject: Re: For each record in SELECT
In-Reply-To: <BA6070D1.17EF4%hierophant@pcisys.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox