Puedes group by building, location
para las filas 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
La condición count(distinct object) < 2
en el having
la cláusula devuelve una combinación de building, location
donde 'WALL'
y 'WINDOW'
ambos no existen.
Vea la demostración
.
Resultados:
| building | location | action |
| -------- | -------- | ------ |
| A | FLOOR2 | FLAG |
| B | FLOOR1 | FLAG |
O con NO 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
)
Vea la demostración .