pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: James Neethling <james@silversphere.co.za>
To: pgsql-performance@postgresql.org
Subject: column totals
Date: Fri, 26 May 2006 11:56:39 +0200
Message-ID: <4476D0D7.1080006@silversphere.co.za> (raw)

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

Attachments:

james.vcf (text/x-vcard, 390B) download 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

view thread (3+ messages)  latest in thread

Message-ID: <4476D0D7.1080006@silversphere.co.za>
Permalink:  ../4476D0D7.1080006@silversphere.co.za/
Also on:    postgresql.org/message-id/4476D0D7.1080006@silversphere.co.za

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: james@silversphere.co.za
  Subject: Re: column totals
  In-Reply-To: <4476D0D7.1080006@silversphere.co.za>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox