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

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: peter pilsl <pilsl(at)goldfisch(dot)at>
Cc: PostgreSQL List <pgsql-general(at)postgresql(dot)org>
Subject: Re: sql-question: sum-function and subqueries?
Date: 2004-07-01 16:21:37
Message-ID: 20040701162137.GA1438@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jul 01, 2004 at 10:56:29 +0200,
peter pilsl <pilsl(at)goldfisch(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bill Montgomery 2004-07-01 16:23:18 Re: backups
Previous Message Dennis Gearon 2004-07-01 15:36:12 permissions