0

员工部门架构如何获取每个部门的详细信息(部门 ID、部门名称)以及每个部门的员工人数。

4

7 回答 7

5

尝试这个

select dept.deptId,
   deptName,
   count(emp.empid) as numb_of_emps
   from department dept inner join employee emp
   on dept.deptid = emp.deptid
   group by dept.deptid
于 2012-05-28T05:25:54.693 回答
3

你可以把它当作 - (正如 Russell Dias 所建议的那样)

select d.deptId,
       deptName,
       count(e.empid) "number of employees"
from department d, employee e
where d.deptid = e.deptid
group by d.deptid,d.deptname
于 2012-05-28T05:20:22.833 回答
0
select d.deptno,dname,count(e.empno) "No of Emp"
from dept d, emp e 
where d.deptno = e.deptno
group by d.deptno,d.dname
于 2014-12-09T05:19:57.243 回答
0

如果您不需要实际的部门详细信息,而只需要部门名称,则可以进一步简化,如下所示:

SELECT department_name, COUNT(*) AS "Number of employees" 
FROM employees group by department;
于 2014-06-18T15:07:48.233 回答
0
SELECT department_name,COUNT(*) FROM employees a,departments b
where a.department_id=b.department_id
group by department_name;
于 2016-01-06T13:14:16.520 回答
0

您可以使用内部联接:

Select  e.EmployeeName,
        d.DepartmentName,
        count(d.DepId)As Total_no_of_Employees
From Department d
Inner join Employee e 
    On d.DepId = e.EmpID
Groub By DepartmentName, Total_no_of_Employees
于 2016-08-29T11:18:25.777 回答
0
select d.deptno, d.dname, count(e.empno) "Number of employees"
from dept d, emp e
where d.deptno = e.deptno
group by d.deptno,d.dname;
于 2016-06-22T21:59:27.670 回答