1

我有以下查询

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) 中使用 event.service 而不是在 event.service=4 上使用

4

2 回答 2

2

我认为你可以使用这样的东西;

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
)
于 2013-09-24T07:39:18.780 回答
0

尝试这个:

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
于 2013-09-24T07:36:52.497 回答