column totals

Поиск
Список
Период
Сортировка
От James Neethling
Тема column totals
Дата
Msg-id 4476D0D7.1080006@silversphere.co.za
обсуждение исходный текст
Ответы Re: column totals  (James Neethling <james@silversphere.co.za>)
Re: column totals  (Ragnar <gnari@hive.is>)
Список 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



Вложения

В списке pgsql-performance по дате отправления:

Предыдущее
От: "Merlin Moncure"
Дата:
Сообщение: Re: is it possible to make this faster?
Следующее
От: James Neethling
Дата:
Сообщение: Re: column totals