如何列出部门ID和名称,然后列出在部门名称下面的部门工作的员工?

时间:2016-03-24 09:23:37

标签: sql

select DEPARTMENT_ID, DEPARTMENT_NAME from DEPARTMENTS
union 
select DEPARTMENT_ID, LAST_name from employees
order by 1, 2;

但基本上是以每个部门都有员工的方式订购......

1 个答案:

答案 0 :(得分:0)

添加辅助排序以在部门组中首先强制部门行。

select 'D' as de, DEPARTMENT_ID, DEPARTMENT_NAME from DEPARTMENTS

union 

select 'E' as de, DEPARTMENT_ID, LAST_name from employees 

order by DEPARTMENT_ID, de, LAST_name ;