Re: Unexpected behavior with CASE statement

From: Rodrigo De León <rdeleonp(at)gmail(dot)com>
To: "Jimmy Choi" <yhjchoi(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Unexpected behavior with CASE statement
Date: 2007-10-03 19:56:53
Message-ID: a55915760710031256i3d104d75g9280486199c61a82@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 10/3/07, Jimmy Choi <yhjchoi(at)gmail(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jimmy Choi 2007-10-03 20:08:11 Re: Unexpected behavior with CASE statement
Previous Message Brian Wipf 2007-10-03 19:05:56 Re: PITR and Compressed WALS