这是关系和Pasenger_detail形式的图片,我写了一个查询来选择seat_no但它不能正常工作。它只显示所有座位按照公交车保留的ID。但要求只显示尚未选择的那些。这是查询
"Select seat_no.seat_no FROM Seat_No Where seat_no.seat_no <= (select br_info.Seats_Reserved from br_info where ((Br_info.br_id)=[forms]![pasenger_detail]![br_id]) AND (Seat_No.seat_no) NOT IN (SELECT Pasenger_Detail.Seat_No FROM Pasenger_Detail WHERE (((Pasenger_Detail.Group_ID)=[forms]![Pasenger_Detail]![Group_ID]) AND ((Pasenger_Detail.BR_ID)=[forms]![Pasenger_Detail]![BR_ID]))));"
答案 0 :(得分:0)
SELECT S.Seat_No
FROM Seat_No AS S
WHERE S.Seat_No Not In
(
SELECT P.Seat_No
FROM BR_Info AS B INNER JOIN Pasenger_Detail AS P ON B.BR_ID = P.BR_ID
WHERE B.BR_ID = Forms!pasenger_detail!BR_ID
AND B.Group_ID = Forms!Pasenger_Detail!Group_ID
)
在上面的查询中,我一起加入BR_Info
和Passenger_Detail
。它是INNER JOIN
,这意味着记录必须同时存在于BR_Info
和Passenger_Detail
中才能被考虑。然后我使用Not In
来获取子查询中未包含的所有Seat_No
。