表格
Hotel (hotelNo, HotelName, city)
Room (roomNo, hotelNo, type, price)
Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo)
Guest (guestNo, guestName, guestAddress)
根据以上表格为以下查询提供结构化查询语言语法:
列出2009年5月,6月和7月的预订房间列表,每天价格超过8000.
我尝试了以下操作,但它无法正常工作:
SELECT *
FROM Booking
WHERE HotleNo IN (SELECT HotelNo FROM Room WHERE Price>8000)
AND (DateFrom>= '2009-05-01' AND dateTo<= '2009-07-31');
答案 0 :(得分:2)
价格是Room属性而不是Hotel属性。但我想你可能会处理几个重叠房间号的酒店,所以你必须匹配roomNo和hotelNo
SELECT *
FROM Booking
JOIN Room on Booking.roomNo=Room.roomNo and Booking.hotleNo=Room.hotleNo
WHERE Room.Price>8000
AND Booking.DateFrom>= '2009-05-01'
AND Booking.dateTo<= '2009-07-31'
编辑:在你的问题中,该字段是hotleNo所以我将坚持使用该字段名称
答案 1 :(得分:1)
您可以尝试以下方法。由于您可以从表预订和会议室中检索所需的所有信息,因此您只需加入2并获取数据。
select B.* from Booking B
left outer join Room R
on R.roomNo = B.roomNo
where B.dateFrom >= '2009-05-01'
and B.dateTo <= '2009-07-31'
and R.price > 8000