-3

在此处输入图像描述

在此处输入图像描述

这是关系和 Pasenger_detail 表格的图片,我写了查询来选择座位号,但它不能正常工作。它只显示根据公共汽车保留 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]))));"
4

1 回答 1

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子查询中不包含的所有内容。

于 2013-09-27T13:13:37.963 回答