X-Original-To: pgsql-general@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 6219B479BA8 for ; Fri, 31 Jan 2003 21:14:44 -0500 (EST) Received: from leo.pcisys.net (leo.pcisys.net [207.76.102.240]) by postgresql.org (Postfix) with ESMTP id 8F9F6476544 for ; Fri, 31 Jan 2003 20:28:29 -0500 (EST) Received: from [192.168.2.15] (moe.rbe45-78.cos.pcisys.net [216.229.45.78]) by leo.pcisys.net (8.12.5/8.12.5) via ESMTP id h111SdCH011055 for ; Fri, 31 Jan 2003 18:28:39 -0700 (MST) env-from (hierophant@pcisys.net) User-Agent: Microsoft-Outlook-Express-Macintosh-Edition/5.0.6 Date: Fri, 31 Jan 2003 18:28:34 -0700 Subject: Re: For each record in SELECT From: Keary Suska To: PostgreSQL Message-ID: In-Reply-To: <1044048077.1380.3.camel@kerberus> Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/1627 X-Sequence-Number: 36748 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"