Re: Unexpected behavior with CASE statement - Mailing list pgsql-general

From Rodrigo De León
Subject Re: Unexpected behavior with CASE statement
Date
Msg-id a55915760710031256i3d104d75g9280486199c61a82@mail.gmail.com
Whole thread Raw
In response to Unexpected behavior with CASE statement  ("Jimmy Choi" <yhjchoi@gmail.com>)
Responses Re: Unexpected behavior with CASE statement
List pgsql-general
On 10/3/07, Jimmy Choi <yhjchoi@gmail.com> wrote:
> I expect to get the following result set:
>
> metric_type | result
> ------------+-------
>     0       |   2
>     1       |   3

Try:

SELECT   metric_type
       , SUM(CASE metric_type
               WHEN 0
                 THEN 1 / val
               WHEN 1
                 THEN val
             END) AS RESULT
    FROM metrics
GROUP BY metric_type
ORDER BY metric_type

pgsql-general by date:

Previous
From: Brian Wipf
Date:
Subject: Re: PITR and Compressed WALS
Next
From: "Jimmy Choi"
Date:
Subject: Re: Unexpected behavior with CASE statement