Re: sql-question: sum-function and subqueries?

Поиск
Список
Период
Сортировка
От Bruno Wolff III
Тема Re: sql-question: sum-function and subqueries?
Дата
Msg-id 20040701162137.GA1438@wolff.to
обсуждение исходный текст
Ответ на sql-question: sum-function and subqueries?  (peter pilsl <pilsl@goldfisch.at>)
Список pgsql-general
On Thu, Jul 01, 2004 at 10:56:29 +0200,
  peter pilsl <pilsl@goldfisch.at> wrote:
>
>
> I have a question to sql and dont know exactely if this is the right
> place to ask. If not I would be glad if anyone could point me to the
> correct group/list/resource. Thnx.
>
> I want to perform a sum-operation in a group by - query and want to
> specify additionaly conditions when to sum.
>
> like: having a table with colums x,y,z
>
> select x,sum(y only if z is 'val1'),sum(y only if z is 'val2') from
> table group by x;

You can use CASE to do this. The CASE function goes inside the sum
function call similar to what you sketched out above.

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

Предыдущее
От: Hervé Piedvache
Дата:
Сообщение: DELETE TABLE xx do not erase index file after a vacuum full ?
Следующее
От: Dennis Gearon
Дата:
Сообщение: Re: backups