From: | "Johnson, Shaunn" <SJohnson6(at)bcbsm(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: multiple counts using CASE |
Date: | 2002-03-19 15:35:26 |
Message-ID: | 73309C2FDD95D11192E60008C7B1D5BB0452E0F6@snt452.corp.bcbsm.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
--Thanks Tom!
--That's just what I needed!
-X
-----Original Message-----
From: Tom Lane [mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us]
Sent: Tuesday, March 19, 2002 10:19 AM
> Wonder if it is possible to get multiple counts
> from ONE query using the CASE statement.
If I'm understanding you correctly, you can't do what you want with
a single aggregate function call, because that will only give you
one result.
Consider something like
select
sum(case when logic = '1' then 1 else 0 end),
sum(case when logic = '2' then 1 else 0 end),
sum(case when logic = '3' then 1 else 0 end)
from ...
I also wonder whether you aren't reinventing the notion of GROUP BY.
F'r instance
select logic, count(*) from ... group by logic;
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Oberpriller, Wade D. | 2002-03-19 15:42:57 | Visual display tool? |
Previous Message | Carsten Zerbst | 2002-03-19 15:32:52 | Reference pg_user ? |