不同查询之间的SQL不同值

不同查询之间的SQL不同值,sql,duplicate-removal,Sql,Duplicate Removal,我有以下疑问 select distinct people.id from people inner join incident on people.id = incident.peopleid where incident.service =4 AND people.id NOT IN ( select incident.peopleid from Incident where incident.service IN =4 AND incident.ServiceInterrupt

我有以下疑问

select distinct 
people.id
from people
inner join incident on people.id = incident.peopleid 
where  incident.service =4
AND people.id NOT IN (
select  incident.peopleid
from Incident
where 
incident.service IN =4
AND incident.ServiceInterrupt != 0
)
这给了我所有属于某个服务的人,他们还没有中断该服务。 我想对服务5和6运行此查询,对于这些结果,只取唯一的人。 到现在为止,我运行了3次查询(每次都更改服务),然后用excel删除重复项!!! 还有别的办法吗

提前谢谢

编辑:更具体地说,我希望从结果中排除服务X中所有仅具有中断服务X的人员。这就是为什么我不能在事件上使用(4,5,6)中的incident.service。service=4

试试这个:

select distinct 
people.id
from people
inner join incident on people.id = incident.peopleid 
where  incident.service IN(4,5,6)
AND incident.ServiceInterrupt != 0

我想你可以用这样的东西

select distinct 
people.id
from people
inner join incident i1 on people.id = i1.peopleid 
where  i1.service in(4,5,6)
AND people.id NOT IN (
select  i2.peopleid
from Incident i2
where 
i2.service = i1.service
AND i2.ServiceInterrupt != 0
)

谢谢,但请不要告诉我第四服务台的人中断了第五或第六服务台。我不想只考虑服务X中只有中断服务X的人。你内心选择的目的是什么?您能否不排除整个事件,而只使用
和incident.ServiceInterrupt!=0
?我需要它来获取其他详细信息,我已经删除了这些详细信息以获取您所看到的内容。这是最主要的。