我想找到容量为100或以上且在星期二中午12点免费(即没有预订)的演讲室(他们的房间代码)。
在房间表中,有rCode&容量。 在roomBooking表中,有dayReq,timeReq& roomCode。
我到目前为止的SQL查询是
SELECT rCode, capacity
FROM room
INNER JOIN roomBooking
ON room.rCode = roomBooking.roomCode
WHERE capacity >= 100;
我想摆脱涉及的结果 dayReq =“Tuesday”AND timeReq =“12:00:00”但我不知道正确的操作符。
答案 0 :(得分:1)
要获得所需内容,您需要left join
(或where
子句中的子查询)。我们的想法是找到所有房间以及房间符合预订标准的任何可能的匹配。然后你想要没有匹配的房间:
SELECT room.rCode, room.capacity
FROM room LEFT JOIN
roomBooking
ON room.rCode = roomBooking.roomCode AND
dayReq = 'Tuesday' AND timeReq = '12:00:00'
WHERE room.capacity >= 100 AND
roomBooking.roomCode IS NULL;
MS Access很多东西都很奇怪,包括多个键的连接。只需使用相关子查询执行此操作:
SELECT room.rCode, room.capacity
FROM room
WHERE NOT EXISTS (SELECT 1
FROM roomBooking
WHERE room.rCode = roomBooking.roomCode AND
dayReq = "Tuesday" AND timeReq = "12:00:00"
) AND
room.capacity >= 100;