Você pode
group by building, location
para as linhas where object in ('WALL', 'WINDOW')
:select building, location, 'FLAG' action
from tablename
where object in ('WALL', 'WINDOW')
group by building, location
having count(distinct object) < 2
A condição
count(distinct object) < 2
no having
cláusula retorna a combinação de building, location
onde 'WALL'
e 'WINDOW'
ambos não existem.Veja a demonstração .
Resultados:
| building | location | action |
| -------- | -------- | ------ |
| A | FLOOR2 | FLAG |
| B | FLOOR1 | FLAG |
Ou com NÃO EXISTE:
select t.building, t.location, 'FLAG' action
from tablename t
where object in ('WALL', 'WINDOW')
and not exists (
select 1 from tablename
where building = t.building and location = t.location and object <> t.object
)
Veja a demonstração .