Re: aggregates and case statements

From: Richard Huxton <dev(at)archonet(dot)com>
To: Garry Saddington <garry(at)schoolteachers(dot)co(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: aggregates and case statements
Date: 2008-11-17 09:32:22
Message-ID: 49213A26.8020307@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Garry Saddington wrote:
> Is there a way to make the following statement return the total of all effort. At the moment it gives a list of sum vs case.
>
>
> select sum(effort),
> CASE WHEN effortandattainment.effort=5 THEN -3
> WHEN effortandattainment.effort=4 THEN -2
> WHEN effortandattainment.effort=3 THEN 1
> WHEN effortandattainment.effort=2 THEN 2
> WHEN effortandattainment.effort=1 THEN 3
>
> END
> from effortandattainment

SELECT sum(effort) FROM effortandattainment;

But I'm guessing that's not what you mean. Can you show what output
you'd like to have?

--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mr. John 2008-11-17 09:47:03 Re: Problem with pg_restore into new database
Previous Message Richard Huxton 2008-11-17 09:31:28 Re: Problem with pg_restore into new database