Anda dapat group by building, location
untuk baris 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
Kondisi count(distinct object) < 2
di having
klausa mengembalikan kombinasi building, location
di mana 'WALL'
dan 'WINDOW'
keduanya tidak ada.
Lihat demo
.
Hasil:
| building | location | action |
| -------- | -------- | ------ |
| A | FLOOR2 | FLAG |
| B | FLOOR1 | FLAG |
Atau dengan NOT EXISTS:
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
)
Lihat demo .