1

我有两个查询,其中qryAvailability1退货日期被阻止预订,而qryAvailability2在任何预订发生之前产生完全可用的日期。

我将它们组合在一个最终的“不匹配”查询中,以定义可供预订的日期:

qry可用性1:

SELECT tblReservations.PropertyID, tblDates.Date
FROM tblReservations, tblDates
WHERE (((tblDates.Date) Between [tblReservations]![CheckIn] And [tblReservations]![CheckOut]));

qry可用性2:

从 tblProperties、tblDates 中选择 tblProperties.PropertyID、tblDates.Date;

最后的“无匹配”查询:

SELECT qryAvailability2.PropertyID, qryAvailability2.Date
FROM qryAvailability2 LEFT JOIN qryAvailability1 ON (qryAvailability2.Date=qryAvailability1.Date) AND (qryAvailability2.PropertyID=qryAvailability1.PropertyID)
WHERE (((qryAvailability1.Date) Is Null))
ORDER BY qryAvailability2.PropertyID, qryAvailability2.Date;

有没有办法将单个查询语句放入 1 个查询而不是三个?

换句话说,我需要用产生它们的 sql 语句替换对它们的引用qryAvailability1qryAvailability2无论我尝试什么都不起作用)。

4

1 回答 1

1

假设您的最终查询有效(我还没有检查过),然后结合所有三个:

SELECT qryAvailability2.PropertyID, qryAvailability2.Date
FROM (
SELECT tblProperties.PropertyID, tblDates.Date FROM tblProperties, tblDates
) qryAvailability2 LEFT JOIN (
SELECT tblReservations.PropertyID, tblDates.Date
FROM tblReservations, tblDates
WHERE (((tblDates.Date) Between [tblReservations]![CheckIn] And [tblReservations]![CheckOut]))
) qryAvailability1 ON (qryAvailability2.Date=qryAvailability1.Date) AND (qryAvailability2.PropertyID=qryAvailability1.PropertyID)
WHERE (((qryAvailability1.Date) Is Null))
ORDER BY qryAvailability2.PropertyID, qryAvailability2.Date;
于 2013-07-12T16:40:47.670 回答