SQL server2000 查询总人数最多的部门,列出部门名称、人数

来源:百度知道 编辑:UC知道 时间:2024/07/02 11:36:07
有二个表:部门信息表为Dept和员工信息表为Employee。
Employee中的Dno外健引自Dept表中的Dno。
部门名称Dname在Dept表中.

Select * From
(
select dept.dname,(Select Count(1) From Employee Where Employee.Dno=dept.Dno) AS count From dept
) TBL Order By count DESC

select c.部门名称,b.人数
from(
select a.dno,sum(a.人数)as 人数
from Employee a
group by a.Dno
)b,Dept c
where c.dno = b.dno
and b.人数 = (

select max(d.人数)
from(
select a.dno,sum(a.人数)as 人数
from Employee a
group by a.Dno
)d
)