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
 General SQL Server Forums
 New to SQL Server Programming
 SQL Query

Author  Topic 

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2013-03-27 : 06:28:49
HI,

I have a table called dbo.table1 which has 2 columns

PracID PatientCode
3 Lung
3 Lung
3 RetPro
11 RetPro
49 Lung
49 RetPro
49 Flu
49 Flu
49 Flu


I want the results to be

PracID PatientCode Count
3 Lung 2
3 RetPro 1
11 RetPro 1
49 Lung 1
49 RetPro 1
49 Flu 3


Thank you


RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2013-03-27 : 06:29:53
so add a count and a group by to the query.
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2013-03-27 : 06:30:36
select
field1
,field2
,count(*)
from table
group by
field1
,field2
Go to Top of Page
   

- Advertisement -