SELECT counts

From: Jayadevan M <Jayadevan(dot)Maymala(at)ibsplc(dot)com>
To: "PostgreSQL Novice List" <pgsql-novice(at)postgresql(dot)org>, pgsql-novice-owner(at)postgresql(dot)org
Subject: SELECT counts
Date: 2010-07-21 09:16:54
Message-ID: OF3D569B61.E52FEDB0-ON65257767.003243F5-65257767.00330BFC@ibsplc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hello all,

I have a table with id and status_v.

create table myt (id integer, status_v varchar(10));
insert into myt values (1,'I');
insert into myt values (1,'P');
insert into myt values (1,'T');
insert into myt values (2,'P');

User gets counts of status records, filtered on some status_v like this
test=# select count(*), status_v from myt where status_v in ('I','P','X')

group by status_v;
count | status_v
-------+----------
1 | I
2 | P
(2 rows)

Is there a way in which I can have the output as
1 | I
2 | P
0 | X

i.e., if there is not data, the count should be displayed as 0.

Regards,
Jayadevan

DISCLAIMER:

"The information in this e-mail and any attachment is intended only for
the person to whom it is addressed and may contain confidential and/or
privileged material. If you have received this e-mail in error, kindly
contact the sender and destroy all copies of the original communication.
IBS makes no warranty, express or implied, nor guarantees the accuracy,
adequacy or completeness of the information contained in this email or any
attachment and is not liable for any errors, defects, omissions, viruses
or for resultant loss or damage, if any, direct or indirect."

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message A. Kretschmer 2010-07-21 09:43:12 Re: SELECT counts
Previous Message A. Kretschmer 2010-07-21 06:59:48 Re: Select only active entries