Search Postgresql Archives

Re: Unexpected behavior with CASE statement

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

 



On 10/3/07, Jimmy Choi <yhjchoi@xxxxxxxxx> 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

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

[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