Results 1 to 2 of 2

Thread: complex query help plz

  1. #1
    Join Date
    Apr 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default complex query help plz

    User selects start and end date....from 25 to 27....

    +---------+------+-----------+
    | day_Num | qty | room_Type |
    +---------+------+-----------+
    | 25 | 2 | single |
    | 25 | 0 | double |
    | 25 | 0 | ensuite |
    | 26 | 6 | single |
    | 26 | 13 | double |
    | 26 | 5 | ensuite |
    | 27 | 1 | single |
    | 27 | 1 | double |
    | 27 | 1 | ensuite |
    +---------+------+-----------+

    room_Type = double and ensuite has ZERO qty....so all the related data with double and ensuite...should not be printed...so the OUTPUT should be:

    +---------+------+-----------+
    | day_Num | qty | room_Type |
    +---------+------+-----------+
    | 25 | 2 | single |
    | 26 | 6 | single |
    | 27 | 1 | single |
    +---------+------+-----------+

    And from here then... the lowest qty should be printed out, so the FINAL OUTPUT should be:

    +---------+------+-----------+
    | day_Num | qty | room_Type |
    +---------+------+-----------+
    | 27 | 1 | single |
    +---------+------+-----------+

    Anyone know what the query should be?

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Try the following query

    Code:
    SELECT * 
    FROM rooms
    WHERE room_type NOT 
    IN (
    'double', 'ensuite'
    )
    AND qty = ( 
    SELECT MIN( qty ) 
    FROM rooms
    WHERE room_type NOT 
    IN (
    'double', 'ensuite'
    )
    GROUP BY day_num
    ORDER BY qty ASC 
    LIMIT 0 , 1 ) 
    ORDER BY qty
    LIMIT 0 , 1;
    
    Make sure that the that you check the table name and field names hat I've mentioned in the query is correct to your table/database.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •