0

您好,这是我的数据库中的 2 个表: 在此处输入图像描述

我试图让酒店在一段时间内可用。在 Rooms 表中定义了房间的类型:例如 Signe:max_guests=1, Triple : max_guests=3 所以对于 10 人预订,我需要类似的东西:

SELECT  SUM(rooms.max_guests * av.RoomAvailable) AS maxPeople 
FROM av AS av INNER JOIN rooms 
ON av.room = rooms.ID AND av.DateofDays BETWEEN '09/28/2012' AND '10/03/2012' 
GROUP BY av.userid
HAVING Count(*) >= 6

但这并不真正符合我的要求..它返回给我可用的 max_people/userID 我只需要检查每个 userID(hotel) 每天是否有 >= 10 (max_people) 可用

谢谢你的帮助

更新:如果我使用这个查询:

SELECT  av.userid, av.DateofDays, SUM(rooms.max_guests * 

av.RoomAvailable) AS maxPeople 
FROM av AS av INNER JOIN rooms 
ON av.room = rooms.ID AND av.DateofDays BETWEEN '09/28/2012' 

AND '10/03/2012' 
GROUP BY av.userid, av.DateofDays
ORDER BY av.userid, av.DateofDays

我明白了: 在此处输入图像描述

4

2 回答 2

1

您必须手动输入天数。

WITH cte AS (
SELECT  av.userid, av.DateofDays, SUM(rooms.max_guests * av.RoomAvailable) AS maxPeople 
FROM av AS av INNER JOIN rooms 
ON av.room = rooms.ID AND av.DateofDays BETWEEN '09/28/2012' AND '10/03/2012' 
GROUP BY av.userid, av.DateofDays
HAVING SUM(rooms.max_guests * av.RoomAvailable) >= 10 
)
select cte.userid 
from cte 
group by av.userid 
having COUNT(*) = 6
于 2012-09-24T08:18:19.280 回答
0

只需将 dateofdays 添加到您的 SELECT 和 GROUP BY。这将只返回天数/酒店 >=10

于 2012-09-24T07:53:48.233 回答