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.
| Author |
Topic |
|
eembme
Starting Member
18 Posts |
Posted - 2007-02-23 : 12:28:23
|
| Site number Patient number1 11 21 32 12 23 13 2How do I count the number of unique patients per unique site numbersite 1 would have 3 patientssite 2 would have 2 patientssite 3 would have 2 patientsThanks! |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
eembme
Starting Member
18 Posts |
Posted - 2007-02-23 : 12:36:02
|
| That does not work because there are a bunch of readings per patient. Even when I use the DISTINCT function, it still counts all of the readings per patient. I was thinking that I would need some type of subquery to do it, but I can't seem to develop one that does not pull all the readings, not just the patient number. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-02-23 : 13:19:52
|
| Did you use DISTINCT the proper way?SELECT [Site number], COUNT(DISTINCT [Patient Number]) AS CountOfPatientsFROM myTable99GROUP BY [Site Number]Peter LarssonHelsingborg, Sweden |
 |
|
|
eembme
Starting Member
18 Posts |
Posted - 2007-02-23 : 13:22:13
|
| Thank you, I was grouping by both |
 |
|
|
|
|
|