Re: sql-question: sum-function and subqueries? - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: sql-question: sum-function and subqueries?
Date
Msg-id 20040701162137.GA1438@wolff.to
Whole thread Raw
In response to sql-question: sum-function and subqueries?  (peter pilsl <pilsl@goldfisch.at>)
List 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 by date:

Previous
From: Hervé Piedvache
Date:
Subject: DELETE TABLE xx do not erase index file after a vacuum full ?
Next
From: Dennis Gearon
Date:
Subject: Re: backups