MySQL 2列查询

时间:2018-09-05 17:27:44

标签: mysql sql

我正在为我的酒店房间开发预订系统(PHP-MySQL)。

我有2张桌子

rooms_table

----------+---------------+----------------+
room_id   |   room_name   |   room_type    |
----------+---------------+----------------+
125       |   name 2      |    deluxe      |
----------+---------------+----------------+
126       |   name 3      |    deluxe      |
----------+---------------+----------------+

rooms_avl_table(我在其中保存房间的不可用日期)

----------+---------------+----------------+
avl_id    |  room_id      |   navl_date    |
----------+---------------+----------------+
12        |    125        | 2018-10-02     |
----------+---------------+----------------+
13        |    125        | 2018-09-05     |
----------+---------------+----------------+

我想列出rooms_avl_table表中未列出的所有房间。例如,如果搜索日期为“ 2018-09-05”,则需要显示所有不包含126(room_id)的房间-这不可用。

3 个答案:

答案 0 :(得分:0)

这应该有效:

select * from rooms_table r
left join rooms_avl a on r.room_id = a.room_id and a.navl_date = '2018-09-05'
where a.room_id is null

答案 1 :(得分:0)

除了LEFT JOIN通过 @isaace 检查NULL解决方案之外,您还可以将Correlated SubqueryNOT IN子句一起使用:

SELECT * FROM rooms_table AS rt 
WHERE rt.room_id NOT IN (SELECT rat.room_id 
                         FROM rooms_avt_table AS rat 
                         WHERE rat.room_id = rt.room_id 
                           AND rat.navl_date = '2018-09-05'
                        )

答案 2 :(得分:0)

不存在

public func lastLineMaxX(message: NSAttributedString, labelWidth: CGFloat) -> CGFloat {
    // Create instances of NSLayoutManager, NSTextContainer and NSTextStorage
    let labelSize = CGSize(width: bubbleWidth, height: .infinity)
    let layoutManager = NSLayoutManager()
    let textContainer = NSTextContainer(size: labelSize)
    let textStorage = NSTextStorage(attributedString: message)

    // Configure layoutManager and textStorage
    layoutManager.addTextContainer(textContainer)
    textStorage.addLayoutManager(layoutManager)

    // Configure textContainer
    textContainer.lineFragmentPadding = 0.0
    textContainer.lineBreakMode = .byWordWrapping
    textContainer.maximumNumberOfLines = 0

    let lastGlyphIndex = layoutManager.glyphIndexForCharacter(at: message.length - 1)
    let lastLineFragmentRect = layoutManager.lineFragmentUsedRect(forGlyphAt: lastGlyphIndex,
                                                                  effectiveRange: nil)

    return lastLineFragmentRect.maxX
}