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 |
|
venkey_no1
Starting Member
2 Posts |
Posted - 2005-03-12 : 08:52:32
|
| Hey guys, i have a small problem. Most of you would have the master database with u. I want to get the output as deptno having the most number of employees.Kindly helpThankyou |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-03-12 : 09:45:41
|
select DeptNum, count(EmployeeId) as EmpNumfrom MyTablegroup by DeptNumorder by 2or select DeptNum, max(EmployeeId) as MaxEmpNumfrom MyTablegroup by DeptNumSee count and max aggregates in BOL = Books OnLine = SQL server help.Go with the flow & have fun! Else fight the flow |
 |
|
|
venkey_no1
Starting Member
2 Posts |
Posted - 2005-03-12 : 14:07:46
|
| spirit1 you are nowhere close to the answer.select DeptNum, count(EmployeeId) as EmpNumfrom MyTablegroup by DeptNumorder by 2This would retrun me 2 columns. I want only one value to be the output---> Deptnoyour other solutionthe same problem with this.select DeptNum, max(EmployeeId) as MaxEmpNumfrom MyTablegroup by DeptNumthe problem is i cannot query 'max(count(*))'The output should be something like thisDeptno-------1001not something like this:Deptno Empnum---------------1001 10so... its not that simple. |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2005-03-12 : 14:19:21
|
| [code]select top 1 DeptNumfrom MyTablegroup by DeptNumorder by count(*) desc[/code]CODO ERGO SUM |
 |
|
|
|
|
|