From: | Keary Suska <hierophant(at)pcisys(dot)net> |
---|---|
To: | PostgreSQL <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: For each record in SELECT |
Date: | 2003-02-01 01:28:34 |
Message-ID: | BA6070D1.17EF4%hierophant@pcisys.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-novice pgsql-sql |
on 1/31/03 2:21 PM, joe666(at)gnovus(dot)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"
From | Date | Subject | |
---|---|---|---|
Next Message | Keary Suska | 2003-02-01 01:49:44 | Re: SQL-question (JOIN) |
Previous Message | Bruno Wolff III | 2003-02-01 01:07:45 | Re: SQL-question (JOIN) |
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew J. Kopciuch | 2003-02-01 02:36:17 | Re: [SQL] For each record in SELECT |
Previous Message | Michiel Lange | 2003-02-01 01:24:14 | Re: where is libpq.so |
From | Date | Subject | |
---|---|---|---|
Next Message | Guy Fraser | 2003-02-01 01:32:08 | Re: CSV import |
Previous Message | Luis Magaña | 2003-01-31 21:21:17 | For each record in SELECT |