相关子查询

时间:2012-11-22 04:59:13

标签: sql ms-access correlated-subquery

试图向客户展示'在过去30天内发票的车辆。 我试过这个:

select C.*, V.*
from CAR_OWNERSHIP O
join VEHICLE V on v.VEH_ID = O.VEH_ID
join CUSTOMER C on C.CUS_ID = O.CUS_ID
where exists (select null
              from INVOICE I
              where I.INV_ID = O.INV_ID and
                    I.INV_DATE >= date() - 30);

我在FROM子句"

中得到了#34;语法错误

1 个答案:

答案 0 :(得分:1)

我已经快速尝试了访问中的查询,但是我得到了同样的错误,但是当我将JOIN更改为特定的连接(如LEFT OUTER JOIN或INNER JOIN)时,该错误消失了,但它被替换为另一个

 Syntax error (missing operator) in query expression in 

我研究了这个并找到了这个post,表明在使用多个连接时访问需要括号

select *
from (CAR_OWNERSHIP O
left outer join CUSTOMER C on C.CUS_ID = O.Cus_ID)
left outer join VEHICLE V on v.VEH_ID = O.VEH_ID
where exists (select null
          from INVOICE I
          where I.INV_ID = O.INV_ID and
                I.INV_DATE >= date() - 30);

我希望这有帮助