来自员工部门架构如何获取每个 部门 (部门ID,部门名称)的详细信息以及每个的员工数量部。
答案 0 :(得分: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
答案 1 :(得分: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
答案 2 :(得分:0)
如果您不需要实际的部门详细信息,只需要部门名称,您可以进一步简化这一点:
SELECT department_name, COUNT(*) AS "Number of employees"
FROM employees group by department;
答案 3 :(得分: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
答案 4 :(得分:0)
SELECT department_name,COUNT(*) FROM employees a,departments b
where a.department_id=b.department_id
group by department_name;
答案 5 :(得分: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;
答案 6 :(得分:0)
您可以使用INNER JOIN:
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