Puoi group by building, location
per le righe 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 condizione count(distinct object) < 2
nel having
la clausola restituisce una combinazione di building, location
dove 'WALL'
e 'WINDOW'
non esistono entrambi.
Guarda la demo
.
Risultati:
| building | location | action |
| -------- | -------- | ------ |
| A | FLOOR2 | FLAG |
| B | FLOOR1 | FLAG |
O con NON ESISTE:
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
)
Guarda la demo .