SELECT counts - Mailing list pgsql-novice

From Jayadevan M
Subject SELECT counts
Date
Msg-id OF3D569B61.E52FEDB0-ON65257767.003243F5-65257767.00330BFC@ibsplc.com
Whole thread Raw
In response to Re: Select only active entries  ("Carel Combrink" <s25291930@tuks.co.za>)
Responses Re: SELECT counts
List 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."






pgsql-novice by date:

Previous
From: "A. Kretschmer"
Date:
Subject: Re: Select only active entries
Next
From: "A. Kretschmer"
Date:
Subject: Re: SELECT counts