column totals

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


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@xxxxxxxxxxxxxxxxxx
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


[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux