我想显示过去两个月没有预约的客户的姓名,地址和电话号码。
表格是:
CLIENT (
ClientNo,
Name,
Sex,
DOB,
Address,
Phone,
Email,
Occupation,
MaritalStatus,
Spouse,
Anniversary
)
RESERVATION
ResNo,
ResDate,
NoOfGuests,
StartDate,
EndDate,
ClientNo,
Status
)
我试过了:
SELECT Name, Address, Phone, ResNo
FROM Client C, Reservation R
WHERE Date_Column >= ResDate R(MONTH, -3, GETDATE())
ORDER BY Name DESC
答案 0 :(得分:0)
尝试使你的状态如
ResDate >= add_months(TRUNC(SYSDATE) + 1, 2)
你也错过了你桌子的JOIN。所以你需要把JOIN放在
中 SELECT C.Name, C.Address, C.Phone, R.ResNo, R.ResDate
FROM Client C INNER JOIN Reservation R ON C.ID = R.ID --Change the column for Joing as per your table structure
WHERE R.ResDate >= add_months(TRUNC(SYSDATE) + 1, 2))
ORDER BY Name ASC;
答案 1 :(得分:0)
您需要外部加入,包含联接中的所有条件,然后过滤掉所有成功的联接:
SELECT C.*
FROM Client C
LEFT JOIN Reservation R ON C.ID = R.ID -- outer join
AND R.ResDate >= add_months(TRUNC(SYSDATE) + 1, 2) -- condition in join
WHERE R.ID IS NULL -- only return missed joins
ORDER BY Name ASC
你想要错过的连接 - 根据条件没有任何保留的连接。这些错过的连接在连接表的列中具有全零空值,因此对这些列(其中一个)为空的过滤将返回没有任何此类保留的客户端。