multiple counts using CASE

Поиск
Список
Период
Сортировка
От Johnson, Shaunn
Тема multiple counts using CASE
Дата
Msg-id 73309C2FDD95D11192E60008C7B1D5BB0452E0F4@snt452.corp.bcbsm.com
обсуждение исходный текст
Ответы Re: multiple counts using CASE  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Jeff Davis
Дата:
Сообщение: Notify argument?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: multiple counts using CASE