REntal表:
CREATE TABLE RENTAL
(
TransactionNo int NOT NULL AUTO_INCREMENT,
MemberID int NOT NULL,
ItemNo char(3) NOT NULL,
RentalEmployeeID varchar(30),
ReturnEmployeeID varchar(30),
Checkout_date DATE,
Checkin_date DATE,
Return_date DATE,
ItemQuantity int(11) NOT NULL,
TotalPrice DOUBLE(10,2) NOT NULL,
ItemFee DOUBLE(10,2),
PRIMARY KEY(TransactionNo),
FOREIGN KEY(MemberID) REFERENCES Member(MemberID),
FOREIGN KEY(ItemNo) REFERENCES Item(Itemno),
FOREIGN KEY(RENTALEMPLOYEEID) REFERENCES Employee(EmployeeID),
FOREIGN KEY(RETURNEMPLOYEEID) REFERENCES Employee(EmployeeID)
)
我正在尝试检索所有为Joe Smith办理入住或退房的人,但我不仅可以办理入住手续或办理入住手续,而且不能同时办理入住手续。我需要一个嵌套子句吗?
SELECT r.ItemNo,
i.Category,
i.Style,
i.Description,
r.`CheckIn_date`,
r.`Checkout_date`,
e.Fname,
e.Lname
FROM MEMBER AS m,
ITEM AS i,
RENTAL AS r,
Employee e
WHERE m.MemberID = r.MemberID
AND m.Fname = 'Joe’
AND m.Lname=’Smith’
AND r.ItemNo = i.ItemNo
AND r.RentalEmployeeID = e.EmployeeID
答案 0 :(得分:0)
我想你是说没有选择包含签到和结帐的记录。查询阻止了这一点。必须是数据缺少这种情况。
答案 1 :(得分:0)
你可以用两个连接替换它,我认为......
SELECT r.ItemNo,
i.Category,
i.Style,
i.Description,
r.`CheckIn_date`,
r.`Checkout_date`,
e_rent.Fname,
e_rent.Lname,
e_rtn.Fname,
e_rtn.Lname
FROM ITEM AS i,
RENTAL AS r,
Member m
LEFT JOIN Employee e_rent ON (r.RentalEmployeeID = e_rent.ID)
LEFT JOIN Employee e_rtn ON (r.RentalEmployeeID = e_rtn.ID)
WHERE m.MemberID = r.MemberID
AND m.Fname = 'Joe’
AND m.Lname=’Smith’
AND r.ItemNo = i.ItemNo