Du kan group by building, location
för raderna 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
Villkoret count(distinct object) < 2
i having
klausul returnerar en kombination av building, location
där 'WALL'
och 'WINDOW'
finns inte båda.
Se demon
.
Resultat:
| building | location | action |
| -------- | -------- | ------ |
| A | FLOOR2 | FLAG |
| B | FLOOR1 | FLAG |
Eller med INTE FINNS:
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
)
Se demon .