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 1B70F9FA42B for ; Fri, 26 May 2006 10:20:16 -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 40429-01 for ; Fri, 26 May 2006 10:20:09 -0300 (ADT) X-Greylist: delayed 03:23:08.398908 by SQLgrey- Received: from ctb-mesg7.saix.net (ctb-mesg7.saix.net [196.25.240.77]) by postgresql.org (Postfix) with ESMTP id 744F19FA279 for ; Fri, 26 May 2006 10:20:09 -0300 (ADT) 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 F21D75E5D for ; Fri, 26 May 2006 15:20:06 +0200 (SAST) Message-ID: <44770077.8010506@silversphere.co.za> Date: Fri, 26 May 2006 15:19:51 +0200 From: James Neethling User-Agent: 1.5 (X11/20060309) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: column totals References: <4476D0D7.1080006@silversphere.co.za> In-Reply-To: <4476D0D7.1080006@silversphere.co.za> Content-Type: multipart/mixed; boundary="------------000807050705010609010201" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/491 X-Sequence-Number: 19278 This is a multi-part message in MIME format. --------------000807050705010609010201 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit James Neethling wrote: > 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? SELECT branch_id, prod_cat_id, sum(prod_profit) as prod_cat_profit, sum(prod_profit) as branch_total > > Or is there a more efficient way? > > Kind Regards, > James > > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Have you searched our list archives? > > http://archives.postgresql.org > --------------000807050705010609010201 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 --------------000807050705010609010201--