MS Access 2010查询等效

时间:2012-11-21 17:44:38

标签: sql ms-access ms-access-2007

这是我与MS Access的第二天,我正在尝试更新现有的应用程序。 这包括更新一些查询。我从来不知道它会如此复杂。 Access中的括号问题真的令人不安,我碰到了墙,我得到了“语法错误”错误。我的SQL查询是这样的:

Select ….(Something)
Into …. (Some Table)
From A
Inner join B on A.ID=B.ID
LEFT OUTER JOIN STAR as C on C.ID = A.ID
    AND C.Data = ’DEMO1’
    AND C.POS= ’POS1’
LEFT OUTER JOIN STAR as D on D.ID = A.ID
    AND D.Data = ’DEMO2’
    AND D.POS= ‘POS2’
LEFT OUTER JOIN STAR as E on E.ID = A.ID
    AND E.Data = ’DEMO3’
    AND E.POS= ‘POS3’

在访问中,我尝试的等价物是:

Select ….
Into ….
From (((A
Inner join B on A.ID=B.ID)
LEFT OUTER JOIN STAR as C (on C.ID = A.ID
    AND C.Data = ’DEMO1’
    AND C.POS= ’POS1’)
LEFT OUTER JOIN STAR as D (on D.ID = A.ID
    AND D.Data = ’DEMO2’
    AND D.POS= ‘POS2’)
LEFT OUTER JOIN STAR as E on E.ID = A.ID
    AND E.Data = ’DEMO3’
    AND E.POS= ‘POS3’

2 个答案:

答案 0 :(得分:0)

考虑

Select ….
Into ….
From 
(A Inner join B on A.ID=B.ID) LEFT OUTER JOIN 
STAR as C on 
C.ID = A.ID AND 
((C.Data =  ’DEMO1’ AND C.POS= ’POS1’) OR
(C.Data =  ’DEMO2’ AND C.POS= ’POS2’) or
(C.Data =  ’DEMO3’ AND C.POS= ’POS3’))

答案 1 :(得分:0)

最后通过括号。

 Select ….
    Into ….
    From (((A
    Inner join B on A.ID=B.ID)
    LEFT OUTER JOIN STAR as C on (C.ID = A.ID
        AND C.Data = ’DEMO1’
        AND C.POS= ’POS1’))
    LEFT OUTER JOIN STAR as D on (D.ID = A.ID
        AND D.Data = ’DEMO2’
        AND D.POS= ‘POS2’))
    LEFT OUTER JOIN STAR as E on (E.ID = A.ID
        AND E.Data = ’DEMO3’
        AND E.POS= ‘POS3’)