X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id DE39D9FA4A7 for ; Wed, 19 Jul 2006 08:14:00 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 98643-03 for ; Wed, 19 Jul 2006 08:13:52 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web31808.mail.mud.yahoo.com (web31808.mail.mud.yahoo.com [68.142.207.71]) by postgresql.org (Postfix) with SMTP id 2D6CB9FA47F for ; Wed, 19 Jul 2006 08:13:52 -0300 (ADT) Received: (qmail 62413 invoked by uid 60001); 19 Jul 2006 11:13:50 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=6Ncicqg18neb4NNVlS6RK1JQ8uhWsF6a07IpNutqZwFHV9sjCWvWw1y2heGjnVUEZUUFOedYCl64wvL4DlWTbIbg6VaGjFN5RmOkzbRUDRnr2avMeUWkKUIPFu06Q4SwGBMyi3XxPdjx/1eWaZWIdRzUqBJpYc+Dm7E4UUAMN9o= ; Message-ID: <20060719111350.62411.qmail@web31808.mail.mud.yahoo.com> Received: from [24.54.196.198] by web31808.mail.mud.yahoo.com via HTTP; Wed, 19 Jul 2006 04:13:50 PDT Date: Wed, 19 Jul 2006 04:13:50 -0700 (PDT) From: Richard Broersma Jr Subject: Re: Table Join (Maybe?) To: Phillip Smith , pgsql-sql@postgresql.org In-Reply-To: <015b01c6ab05$d77f7b00$9b0014ac@ITPhil> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/245 X-Sequence-Number: 25819 > I have two tables: > 1. Sales figures by date and customer. > 2. Customer details - including their Geographic State > I need to extract a report from the first table (I can do that!), and in > that report order by their State (I can do that too!), but I also need a > summary of all the customers in each state, below the end of each state, and > have a grand total at the bottom. > Eg: > Customer 1 State 1 $100.00 > Customer 2 State 1 $100.00 > State 1 $200.00 > Customer 3 State 2 $100.00 > Customer 4 State 2 $100.00 > State 2 $200.00 > Grand Total $400.00 > Does anyone have any magic pointers for me? I've been playing with SELECT > INTO as 2 queries (the individual customers, then the summary figures added > to the temp table) but I end up with ROWS IN FIRST QUERY * ROWS IN SECOND > QUERY instead of them all sorted together nicely :-( I do not believe that a single "query" will give you what you want here. YOU could have 3 seperate queries: 1 for customer detail by state. 1 for state total 1 for grand total However, if you use a reporting tool like crystal or others, they have the ability to generate summaries exactly as you are referring to here. you would only need to pass it the query on total per customer. The reporting utility has a groupby feature where it would group the customers by state for your. In the group by summary it would automaticly display state total. Then if the report footer you could add a grand total summary for all of the records you passed to the report. The following link show some of the reporting programs that you can use. http://www.postgresql.org/community/survey.43 Regards, Richard Broersma Jr.