1789
查出员工所属的直属部门。
返回结果 没有顺序要求 。
表:Employee
+---------------+---------+ | Column Name | Type | +---------------+---------+ | employee_id | int | | department_id | int | | primary_flag | varchar | +---------------+---------+
select employee_id, department_id
from Employee
where primary_flag='Y'
union
select employee_id, department_id
from Employee
group by employee_id
having count(department_id)=1