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
 Individual Count

Author  Topic 

satheesh
Posting Yak Master

152 Posts

Posted - 2011-05-05 : 05:58:33
Dear All

I have agentid,agentname and customerid in a cst table

There are many different agent. So my table contains around 1000 unique agentid and agent name

Now i want to count how many customer comes through each agent

ie the result be

agnetid agentname Total

100 XXX 2345(total customer comes through this agent xxx)
200 YYY 100

How to do this individual count in a single query?Any help would be highly appreicated

Regards,
SG

select count(customerid) from cst

gives total like (2445) but i need to find by each agent.

Regards,
SG

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2011-05-05 : 06:02:53
SELECT agentid,
agentname,
COUNT(customerid) AS AgentCustomersCount
GROUP BY agentid,
agentname

--------------------------
http://connectsql.blogspot.com/
Go to Top of Page
   

- Advertisement -