Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

group by clause with where clause should return count zero also

$
0
0

Dear friends

SELECT * FROM A

1A ACCEPT
2AACCEPT
3CACCEPT
4CACCEPT
5BHOLD
6GHOLD
7GHOLD
8BREJECT
9GREJECT
10HREJECT
11HREJECT
12ANEW
13HREJECT
14HNEW
15CNEW
16DNEW
17ENEW
18DACCEPT
19DACCEPT
20FACCEPT
21INULL

This is my table.

SELECT DISTINCT(PROD) FROM A
A
B
C
D
E
F
G
H
I

These are the products i have.

SELECT PROD,ISNULL(COUNT(*),0) FROM A WHERE STATUS='ACCEPT' GROUP BY PROD
A2
C2
D2
F1

When i execute this i am getting the above result

But my requirement :

A   2
B   0
C   2
D   2
E   0
F   0
G   0
H   0
I    1

How to achieve it.

please help me

thanks in advance



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>