X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 25E62DB335 for ; Sat, 29 Oct 2005 14:18:48 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 09319-06 for ; Sat, 29 Oct 2005 17:18:46 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.197.194]) by svr1.postgresql.org (Postfix) with SMTP id 3718ADB34A for ; Sat, 29 Oct 2005 14:18:46 -0300 (ADT) Received: (qmail 4439 invoked by uid 500); 29 Oct 2005 17:20:37 -0000 Date: Sat, 29 Oct 2005 12:20:36 -0500 From: Bruno Wolff III To: jerry@blumenthalsoftware.com Cc: pgsql-sql@postgresql.org Subject: Re: Aggregate versus lineitem report Message-ID: <20051029172036.GB30316@wolff.to> Mail-Followup-To: Bruno Wolff III , jerry@blumenthalsoftware.com, pgsql-sql@postgresql.org References: <435909FD.5040904@comcast.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <435909FD.5040904@comcast.net> User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.006 required=5 tests=[AWL=0.006] X-Spam-Score: 0.006 X-Spam-Level: X-Archive-Number: 200510/392 X-Sequence-Number: 23245 On Fri, Oct 21, 2005 at 11:32:13 -0400, Jerry Blumenthal wrote: > How do you get a report that lists items and then produces a sum at the > end. Like this: > > name date amount1 amount2 > name date amount1 amount2 > name date amount1 amount2 > > totals sum(amount1) sum(amount2) > > The sql command I am using now is > > SELECT SUM(Tcode.T_amount) Fees, > SUM(Tcharges.T_discount) Discount, > Tcode.T_prov Provider > FROM "C:\zz\Tcode.DAT" Tcode > INNER JOIN "C:\zz\Tcharges.DAT" Tcharges > ON Tcode.T_acctnum = Tcharges.T_acctnum > AND Tcode.T_link = Tcharges.T_link > WHERE (((Tcode.T_posted BETWEEN "01/01/2004" AND "01/31/2004") > AND (Tcode.T_tcode < 30000))) > GROUP BY Provider > > And that shows a list of amounts, for each provider, but I want to be > able to show all the line items that added up to those totals. (I didnt > include the group by provider issue in my question because that is nice > but not necessary- I can always just do one provider at a time with a > clause like "WHERE provider = 1") Normally you would use two separate queries to do this. If you really need to combine them for some reason you can use UNION ALL and some contortions to make sure the two subselects have the same number of columns and that the rows appear in the correct order.