我有一个带有列名和部门的员工配置单元表。其中1名员工可以属于多个部门。
name, department
xxx,finance
xxx,hr
xxx,transport
xxx,sale
yyy,finance
yyy,hr
yyy,transport
zzz,finace
zzz,hr
zzz,transport
zzz,sale
我需要知道不属于" sale"的员工姓名。部。
答案 0 :(得分:0)
您可以编写子查询来提取销售中的所有名称。然后将该查询的结果加入您的表格。
select
results.name,
results.department
from
(select e.name
from employee e
where e.department='sale' group by e.name) invalid_names
right join
(select
e.name,
e.department
from employee e) results
on invalid_names.name = results.name
where invalid_names.name is null;
我想有更好的方法可以做到这一点,但这应该有效:)
答案 1 :(得分:0)
至于蜂巢0.13
Select name from employee
where employee.name not in
(select name from employee where department = 'sale')
group by name;
希望员工的名字是独一无二的。