就我所知,输出应该是该部门的负责人在同一列的department_name下
SELECT department_id, department_name
FROM (SELECT d.department_id, d.department_name, 0 AS ent
FROM departments d
UNION ALL
SELECT d.department_id, '--Department Head: '||e.last_name, 1 AS ent
FROM employees e INNER JOIN departments d ON e.manager_id = d.manager_id)
GROUP BY department_id, ent, department_name
ORDER BY department_id, ent, department_name;
我重写了这个问题,但我仍然不知道如何让每个分区的经理......
10 Administration 20 Marketing 20 --Department Head: Fay 30 Purchasing 30 --Department Head: Baida 30 --Department Head: Colmenares 30 --Department Head: Himuro 30 --Department Head: Khoo 30 --Department Head: Tobias 40 Human Resources 50 Shipping 50 --Department Head: Atkinson 50 --Department Head: Bissot 50 --Department Head: Bull
Department_ID Department_name 10 Administration 10 Manager: Neena 20 Marketing 20 Manager: Harstrein 30 Purchasing 30 Manager: Popp