【发布时间】:2016-06-29 14:52:29
【问题描述】:
我总是在使用 Access SQL 时遇到问题。该语法要求随机添加括号或移动与 SQL Server 不同的内容。有谁知道这里可能出现什么语法错误?错误集中在FROM 子句周围。我知道其他条款没问题,但我留下了它们以供参考。
更新:进一步简化了代码。我主要关心 3 个FROM 子句。
SELECT
...
FROM
(((maintable
INNER JOIN othertable ON (maintable.A = othertable.A) AND (maintable.B = othertable.B))
INNER JOIN
(SELECT
...
FROM
(thirdtable)
INNER JOIN fourthtable ON thirdtable.blah = fourthtable.blah
WHERE
fourthtable.something <> 1
GROUP BY
...
) AS innerselect1 ON (othertable.item = innerselect1.item) AND (othertable.whse = innerselect1.whse)) AS table1)
JOIN (
SELECT ...
FROM (othertable INNER JOIN maintable ON othertable.item = maintable.item)
GROUP BY ...
HAVING ...
) AS table2 ON table1.item = table2.item
WHERE
...
GROUP BY
...
HAVING
...
UNION ALL
SELECT
...
FROM
(((maintable
INNER JOIN othertable ON (maintable.A = othertable.A) AND (maintable.B = othertable.B))
INNER JOIN
(SELECT
...
FROM
(thirdtable)
INNER JOIN fourthtable ON thirdtable.blah = fourthtable.blah
WHERE
fourthtable.something <> 1
GROUP BY
...
) AS innerselect1 ON (othertable.item = innerselect1.item) AND (othertable.whse = innerselect1.whse)) AS table1)
LEFT JOIN (
SELECT ...
FROM (othertable INNER JOIN maintable ON othertable.item = maintable.item)
GROUP BY ...
HAVING ...
) AS table2 ON table1.item = table2.item
WHERE
table2.item IS NULL
GROUP BY
...
HAVING
...
UNION ALL
SELECT
...
FROM
(((maintable
INNER JOIN othertable ON (maintable.A = othertable.A) AND (maintable.B = othertable.B))
INNER JOIN
(SELECT
...
FROM
(thirdtable)
INNER JOIN fourthtable ON thirdtable.blah = fourthtable.blah
WHERE
fourthtable.something <> 1
GROUP BY
...
) AS innerselect1 ON (othertable.item = innerselect1.item) AND (othertable.whse = innerselect1.whse)) AS table1)
RIGHT JOIN (
SELECT ...
FROM (othertable INNER JOIN maintable ON othertable.item = maintable.item)
GROUP BY ...
HAVING ...
) AS table2 ON table1.item = table2.item
WHERE
table1.item IS NULL
GROUP BY
...
HAVING
...
;
【问题讨论】:
-
Access 当时只能连接两个表。你需要很多括号。
-
有趣,我不知道。