Results 1 to 2 of 2
  1. #1
    Epidural is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    15

    Question Very Complex Query Help

    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..

  2. #2
    Epidural is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    15
    Still no deal.. closest thing I've gotten is:

    Code:
    SELECT tblBuilding.LongName FROM tblBuildings
    GROUP BY Building HAVING (
    COUNT(SELECT DISTINCT tblDoors.Room, tblDoors.LeadsTo FROM tblDoors WHERE Entrance=-1 AND Criteria=-1)
    /
    COUNT(SELECT DISTINCT tblDoors.Room, tblDoors.LeadsTo FROM tblDoors WHERE Entrance=-1)
    < 0.5
    )
    But it's incorrect syntax of some sort.. Can't have aggregate expression in HAVING?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Complex Query.... I think?
    By Dannat in forum Queries
    Replies: 6
    Last Post: 02-14-2012, 01:22 PM
  2. Query is too Complex
    By ihealy1 in forum Queries
    Replies: 2
    Last Post: 11-18-2011, 04:46 PM
  3. Complex Query
    By amotto11 in forum Queries
    Replies: 5
    Last Post: 09-02-2011, 07:43 AM
  4. Help with complex Query
    By CEV in forum Queries
    Replies: 1
    Last Post: 03-12-2011, 06:54 AM
  5. Help with complex query (for me at least)
    By GrindEspresso in forum Queries
    Replies: 5
    Last Post: 01-26-2011, 11:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums