Skip site navigation (1) Skip section navigation (2)

column totals

From: James Neethling <james(at)silversphere(dot)co(dot)za>
To: pgsql-performance(at)postgresql(dot)org
Subject: column totals
Date: 2006-05-26 09:56:39
Message-ID: 4476D0D7.1080006@silversphere.co.za (view raw or flat)
Thread:
Lists: pgsql-performance
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



Attachment: james.vcf
Description: text/x-vcard (392 bytes)

Responses

pgsql-performance by date

Next:From: wmiroDate: 2006-05-26 12:04:56
Subject: Why the 8.1 plan is worst than 7.4?
Previous:From: Merlin MoncureDate: 2006-05-26 04:47:35
Subject: Re: is it possible to make this faster?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group