Search Postgresql Archives

Re: aggregates and case statements

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux