I have a table with Building name, such as A, B, C. These building names could be repeated. I have another column which has the floor. Such as floor 1 ,floor 2. Again there could be multiple floor 1 for every building. There is a third column which has object present such as television, bricks, fans. I want to check for every combination of building with corresponding floors, such as Building A - floor 1, Building A- floor 2, if an object 'brick' exists then 'wall' must exist.
EXAMPLE DATA: For every building and location, if 'WALL' exists , 'WINDOW', 'WINDOW1' or 'WINDOW2' must exist, ELSE FLAG
BUILDING LOCATION OBJECT
A FLOOR1 WALL
A FLOOR1 WINDOW
A FLOOR2 WALL
B FLOOR1 WALL
C FLOOR1 WALL
C FLOOR1 WINDOW
DESIRED OUPUT
BUILDING LOCATION ACTION
A FLOOR2 FLAG
B FLOOR1 FLAG
I have tried using GROUP BY, DISTINCT, WHERE EXISTS, but I cant seem to come up with the right logic.