So here's the deal (this is not a repost of a previous, things have changed since then and gotten harder):
I have 3 tables: tblBuildings, tblRooms, tblDoors.
The buildings and rooms tables are pretty obvious, the doors table holds the following:
tblDoors.Entrance
tblDoors.Room
tblDoors.Building
tblDoors.OuterRoom
tblDoors.Number
tblDoors.Condition
Entrance holds yes/no if it is an entrance door
Buildings holds a reference to the ID of the building the door is in
Room holds a reference to the ID of the room that the door swings INTO.
OuterRoom holds a reference to the ID of the room that the door swings AWAY FROM
Number is the number (when counting left to right) of the door if there is more than one with the same conditions (ie double doors, large entranceways etc: same rooms, different door)
Condition is a yes/no which determines if the door meets a certain, known, preset criteria.
So my problem is this:
I need to know if a building has at least 50% of its entrances which have Condition=YES. Not hard. However, I need refer to a set of entrance doors (ie Number 1, 2, 3, 4 doors) as ONE "Entrance". Though they still have to EACH be classified as an entrance door, they collectively make one entrance to the building.
I need an SQL along the lines of "Show all Buildings that have at less than 50% of EntranceWAYS (not doors, but sets of doors) which have Condition=TRUE"
Now the best way I can see is to group all entrance doors which lead to the same room (meaning they must be part of the same entrance way), compare the number of entrance ways which have Condition=YES to the number with Condition=NO and see if YES > NO. But the SQL of this is giving me migraines.
Because I know you guys like a challenge..