X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id A59AA9FA7BA for ; Fri, 26 May 2006 07:26:55 -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 76909-09 for ; Fri, 26 May 2006 07:26:48 -0300 (ADT) X-Greylist: delayed 00:29:47.045594 by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id D0C2C9FA2E6 for ; Fri, 26 May 2006 07:26:48 -0300 (ADT) Received: from ctb-mesg7.saix.net (ctb-mesg7.saix.net [196.25.240.77]) by svr4.postgresql.org (Postfix) with ESMTP id 671F55B09CE for ; Fri, 26 May 2006 09:56:59 +0000 (GMT) Received: from [192.168.0.8] (dsl-146-254-85.telkomadsl.co.za [165.146.254.85]) by ctb-mesg7.saix.net (Postfix) with ESMTP id 94C8C3BC1 for ; Fri, 26 May 2006 11:56:54 +0200 (SAST) Message-ID: <4476D0D7.1080006@silversphere.co.za> Date: Fri, 26 May 2006 11:56:39 +0200 From: James Neethling Reply-To: pgsql-performance@postgresql.org User-Agent: 1.5 (X11/20060309) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: column totals Content-Type: multipart/mixed; boundary="------------040003010701040104030006" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/490 X-Sequence-Number: 19277 This is a multi-part message in MIME format. --------------040003010701040104030006 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi There, I've got a situation where I need to pull profit information by product category, as well as the totals for each branch. Basically, something like SELECT branch_id, prod_cat_id, sum(prod_profit) as prod_cat_profit FROM () as b1 WHERE x = y GROUP BY branch, prod_cat_id Now, I also need the branch total, effectively, SELECT branch_id, sum(prod_profit) as branch_total FROM () as b1 WHERE x = y GROUP BY branch_id. Since the actual queries for generating prod_profit are non-trivial, how do I combine them to get the following select list? Or is there a more efficient way? Kind Regards, James --------------040003010701040104030006 Content-Type: text/x-vcard; charset=utf-8; name="james.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="james.vcf" begin:vcard fn:James Neethling n:Neethling;James org:Silver Sphere Business Solutions adr:Centurion Business Park A2;;25633 Democracy Way;Prosperity Park;Milnerton;Cape Town;7441 email;internet:james@silversphere.co.za title:Managing Member tel;work:27 21 552 7108 tel;fax:27 21 552 7106 tel;cell:27 83 399 2799 x-mozilla-html:FALSE url:http://www.silversphere.co.za version:2.1 end:vcard --------------040003010701040104030006--