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 2008 Forums
 Transact-SQL (2008)
 query for unique departments with employee count

Author  Topic 

kpgraci
Yak Posting Veteran

68 Posts

Posted - 2011-01-12 : 17:20:03
I have a table with:

PersonName
Department

I want a result data set with a unique list of departments and the number of people in that department, for example:

Sales 14
Marketing 30
Management 12

I can't even begin to get going on this...what would the query be?




kpg

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2011-01-12 : 17:32:33
Assuming that each combination of Department and PersonName is unique with only one entry in the table:
select
Department,
count(*) as NumberOfPeople
from
MyTable
group by
Department
order by
Department






CODO ERGO SUM
Go to Top of Page
   

- Advertisement -