multiple counts using CASE - Mailing list pgsql-general

From Johnson, Shaunn
Subject multiple counts using CASE
Date
Msg-id 73309C2FDD95D11192E60008C7B1D5BB0452E0F4@snt452.corp.bcbsm.com
Whole thread Raw
Responses Re: multiple counts using CASE  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general

Howdy

Running Postgres 7.1.3 on RedHat Linux 7.2 kernel
2.4.7 - 10.

Wonder if it is possible to get multiple counts
from ONE query using the CASE statement.

I'm trying to set something up like this:

select count (*)
case
        when logic = '1' then 'First'
        when logic = '2' then 'Second'
        when logic = '3' then 'Third'
        else 'Error'
end as 'Count'
from temp_table
;

I wonder if this is even possible?  Maybe I can
try to create a variable (place holder) and
loop?  I don't want to have to create many
versions of one program to count for each "logic"
in the table.

Suggestions?

Thanks!

-X

pgsql-general by date:

Previous
From: Jeff Davis
Date:
Subject: Notify argument?
Next
From: Tom Lane
Date:
Subject: Re: multiple counts using CASE