用了union联合查询,将一个问题分成两个子问题。union联合查询会自动去除重复选项,如果想全部显示,使用 union all连接。
# Write your MySQL query statement below
select employee_id,department_id
from Employee
group by employee_id
having count(department_id) = 1
union
select employee_id,department_id
from Employee
where primary_flag = 'Y'