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 |
vinay.a
Starting Member
20 Posts |
Posted - 2008-08-12 : 02:56:09
|
hi,I have a table of the following form:EmpName---Department--------------------aaa-------Salesbbb-------Financeccc-------Financeddd-------Productioneee-------Salesfff--------Financeggg-------Productionhhh-------Finance ---------------------I want to display the department and the count of employees of each department as follows:Department----EmpCount----------------------Finance--------2Production-----2Sales----------4----------------------I refered some articles on inner join, etc. but did not find luckAny help will be very useful. Thank you.regards,vinay |
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-08-12 : 03:04:37
|
i'm gonna assume you got the counts in your example the wrong way round for sales and finance?? use count(distinct empname)as in...select department, count(distinct empname)from YourTablegroup by departmentEm |
 |
|
vinay.a
Starting Member
20 Posts |
Posted - 2008-08-12 : 06:19:31
|
thanks, its working fine,regards,vinay |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-08-12 : 06:22:50
|
Why the distinct on empname ?This will also do the jobselect department, count(*)from YourTablegroup by department KH[spoiler]Time is always against us[/spoiler] |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-12 : 08:14:23
|
quote: Originally posted by khtan Why the distinct on empname ?This will also do the jobselect department, count(*)from YourTablegroup by department KH[spoiler]Time is always against us[/spoiler]
may be influenced by title of the thread |
 |
|
|
|
|