Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 count .. IF

Author  Topic 

jung1975
Aged Yak Warrior

503 Posts

Posted - 2005-08-16 : 15:18:08
I have a table looks like

p_id HBL LBL risk
1008 120 90 MND
1008 111 90 NOD
1009 129 85 MND
1010 130 97 NOD

I would like to count the total records, but if p_id is same then I would like to count only MND record( not NOD)
,so the total count should be 3 instead of 4



X002548
Not Just a Number

15586 Posts

Posted - 2005-08-16 : 15:47:25
SELECT COUNT(DISTINCT p_id)

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

jung1975
Aged Yak Warrior

503 Posts

Posted - 2005-08-16 : 15:58:39
Actually, I want to count how many people are in MND and how many are in NOD

MND = 2 and NOD = 1


Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-08-16 : 16:38:53
Read the Hint link in the sig so we can all be clear about what your req's are

SELECT risk, COUNT(DISTINCT p_id) FROM myTable99 GROUP BY risk


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page
   

- Advertisement -