如何显示所有经理的姓氏和编号以及下属的员工数量

时间:2018-10-03 12:59:03

标签: sql oracle11g

这是架构enter image description here \, 我尝试使用内部组件,但结果是垃圾

SELECT
     employees.last_name   AS last_name,
     COUNT(employees.job_id) AS EMPLOYEES_Subordinates,
     COUNT(employees.manager_id) AS Manager_Numbers
 FROM
     employees left
     JOIN departments ON departments.manager_id = employees.manager_id
 GROUP BY
     employees.last_name
 ORDER BY
 EMPLOYEES_Subordinates desc;

(我真的不知道如何从hr向您显示表格) 如果有任何一个人具有Oracle数据库的人力资源并有时间帮助我,我将非常高兴。

1 个答案:

答案 0 :(得分:0)

不太确定,请尝试以下操作:

SELECT 
    e.LAST_NAME
    ,(SELECT COUNT(ee.EMPLOYEE_ID) FROM EMPLOYEES ee WHERE ee.MANAGER_ID = e.EMPLOYEE_ID) AS 'NUMBER OF WORKERS'
FROM EMPLOYEES e
WHERE MANAGER_ID IS NULL