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
 Function help

Author  Topic 

joep92
Starting Member

1 Post

Posted - 2012-04-09 : 11:45:55
SALESPERSONID SALESPERSONNAME TERRITORYID
------------- ------------------------- -----------
1 Doug Henny 2
8 Fred Flinstone 2
3 William Strong 3
9 Mary James 4
4 Julie Dawson 4
5 Jacob Winslow 5
2 Robert Lewis 13
6 Pepe Lepue 13
10 Mary Smithson 15


how would I display the territory id and the amount of sales people that work in that territory. For example territory 2 should show 2 sales people working there

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-09 : 11:48:07
A simple group by will do the trick!

SELECT TERRITORYID,COUNT(SALESPERSONID) AS SalesPersonCnt
FROM Table
GROUP BY TERRITORYID


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -