I have a SQL statement (below) for SQL Server 2008 DB that returns a Division, a Dept Code, and a count of employees grouped by the Division & Dept Code.
All I want to display is the MAX count, so a sample of my SQL is:
Divison Dept_Code Count_Emp
1011 100 1
1011 101 122
1011 123 1
1011 198 1
1011 199 1
1012 100 3
1012 101 36
1012 123 2
1012 198 1
But all I want to display is:
Division Dept Count_Emp
1011 101 122
1012 101 36
select di.divId Division, Dpt.Dept_Code, count(Emp.Emp_id)
from division di, Department Dpt, Employee Emp
where Emp.DIVID = di.DIVID and
Emp.Dept_Code = Dpt.Dept_Code and
EMP.status = 'A'
group by di.divId, Dpt.Dept_Code
order by 1,2
How can this be acheived? I've applied all of my SQL skills but can't figure this out. Will this need multiple nested queries or a Having Clause would work?
Please help.
Thanks!
All I want to display is the MAX count, so a sample of my SQL is:
Divison Dept_Code Count_Emp
1011 100 1
1011 101 122
1011 123 1
1011 198 1
1011 199 1
1012 100 3
1012 101 36
1012 123 2
1012 198 1
But all I want to display is:
Division Dept Count_Emp
1011 101 122
1012 101 36
select di.divId Division, Dpt.Dept_Code, count(Emp.Emp_id)
from division di, Department Dpt, Employee Emp
where Emp.DIVID = di.DIVID and
Emp.Dept_Code = Dpt.Dept_Code and
EMP.status = 'A'
group by di.divId, Dpt.Dept_Code
order by 1,2
How can this be acheived? I've applied all of my SQL skills but can't figure this out. Will this need multiple nested queries or a Having Clause would work?
Please help.
Thanks!