用sql语句写,有谁能给个有参考价值的答案?

来源:百度知道 编辑:UC知道 时间:2024/06/07 05:53:18
数据库构成
Hotel (hotelNo,hotelName,city)
Room(roomNo,hotelNo,type,price)
Booking(hotelNo,guestNo,dateFrom,dateTo,roomNo)
Guest(guestNo,guestName,guestAddress)
问题:
List the details of all rooms at the Grosvenor Hotel, including the name of guest staying in the room, if the room is occupied.
还有一题:
what is the average number of bookings for each hotel in August?(求8月份的平均订房数)
上一题翻译:列出Grosvenor旅馆各个房间的详细资料,若该房间已有人入住,则同时列出该客人名字

List the details of all rooms at the Grosvenor Hotel, including the name of guest staying in the room, if the room is occupied.

?????????

等我学会E文后再来回你!!!

===============================================================
列出Grosvenor旅馆各个房间的详细资料,若该房间已有人入住,则同时列出该客人名字:

select a.hotelNo,a.hotelName,a.city,b.roomNo,b.type,b.price,
isnull((select c.guestName from Guest c,Booking d where c.guestNo=d.guestNo)," ") as guestName
from Hotel a,Room b
where a.hotelNo=b.hotelNo
and hotelName ='Grosvenor'

由于没有表数据测试,大概是这样。

============================================================

8月份订房数:

declare @FromDate nvarchar(30)
declare @ToDate nvarchar(30)

set @FromDate='2008-08-01'
set @ToDate='2008-08-31'

select count(*) from Booking a,Hotel b,Room c where a.hotelNo=b.hotelNo and a.hotelNo=c.hotelNo and b.hotelName ='Grosveno