请在ms访问中解决此选择查询

时间:2013-09-27 11:05:49

标签: database vba ms-access ms-access-2007 access-vba

enter image description here

enter image description here

这是关系和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]))));"

1 个答案:

答案 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_InfoPassenger_Detail。它是INNER JOIN,这意味着记录必须同时存在于BR_InfoPassenger_Detail中才能被考虑。然后我使用Not In来获取子查询中未包含的所有Seat_No