查找那些eventId的所有行的结果,其中对于具有特定位置和子位置的eventId存在一行,但是不存在具有该位置和空子位置的任何行。我使用EXCEPT关键字在MS SQL中完成了它;但是,MS Access在EXCEPT上失败。有没有办法在MS Access中执行此查询:
SELECT Distinct eventID FROM table WHERE Position = '123' AND SubPosition = 'ABC'
AND pool = 'something'
AND Status = 'active'
AND area = '1'
EXCEPT
SELECT Distinct eventID FROM table WHERE Position = '123' AND SubPosition IS NULL
AND pool = 'something'
AND Status = 'active'
AND area = '1'
由于
答案 0 :(得分:0)
沿着外部联接的行找到没有空匹配的位置,然后过滤没有空匹配。
SELECT *
FROM (select * from Table1 where subposition is not null) as hasSubPosition
left join (select * from Table1 where subposition is null) AS noSubPosition
on
hasSubPosition.eventid = noSubPosition.eventid and
hasSubPosition.position = noSubPosition.position and
hasSubPosition.pool = noSubPosition.pool and
hasSubPosition.status = noSubPosition.status and
hasSubPosition.area = noSubPosition.area
where noSubPosition.eventid is null