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
 SQL Server Development (2000)
 Counting Query

Author  Topic 

SamC
White Water Yakist

3467 Posts

Posted - 2002-06-07 : 14:04:53
I've got a table of employees with a field called "office"

I can count all users in an office using
SELECT COUNT(DISTINCT OFFICE) FROM USERS

I can get a recordset of all the offices
SELECT DISTINCT OFFICE FROM USERS

Seems like a hybrid of the two statements could be constructed that will return a recordset of all the unique office names and the count of employees in each office?

Thanks,
Sam

izaltsman
A custom title

1139 Posts

Posted - 2002-06-07 : 14:18:55
You need to take advantage of the GROUP BY clause (you are asking for a count of users, grouped by office)...

SELECT OFFICE, COUNT(*) FROM USERS GROUP BY OFFICE


Go to Top of Page
   

- Advertisement -