我正在尝试消除不必要的重复查询结果。要点是所有表中都存在[CUSIP]字段,但[IDD_FS]以外的所有表中都存在[4DTYR]字段。
我之前只通过[CUSIP]字段加入了表格,这导致查询产生了不需要的重复结果(某种类型的包含该字段的所有表中的[4DTYR]的排列)。
然后,我在下面进行了修改。但是,现在我收到JOIN语法错误。有人可以帮忙吗?谢谢!
FROM
(((IDX_FS LEFT JOIN DATA_BS
ON IDX_FS.CUSIP = DATA_BS.CUSIP)
LEFT JOIN DATA_Footnotes
ON IDX_FS.CUSIP = DATA_Footnotes.CUSIP)
LEFT JOIN DATA_IS
ON IDX_FS.CUSIP = DATA_IS.CUSIP)
LEFT JOIN DATA_SP
ON IDX_FS.CUSIP = DATA_SP.CUSIP
AND (((DATA_BS LEFT JOIN DATA_IS
ON DATA_BS.CUSIP = DATA_IS.CUSIP
AND DATA_BS.4DTYR = DATA_IS.4DTYR)
LEFT JOIN DATA_SP
ON DATA_BS.CUSIP = DATA_SP.CUSIP
AND DATA_BS.4DTYR = DATA_SP.4DTYR)
LEFT JOIN DATA_Footnotes.4DTYR
ON DATA_BS.CUSIP = DATA_Footnotes.CUSIP
AND DATA_BS.4DTYR = DATA_Footnotes.4DTYR
答案 0 :(得分:1)
您似乎有一个(
太多:
FROM
(
(
(IDX_FS LEFT JOIN DATA_BS ON IDX_FS.CUSIP = DATA_BS.CUSIP)
LEFT JOIN DATA_Footnotes ON IDX_FS.CUSIP = DATA_Footnotes.CUSIP
)
LEFT JOIN DATA_IS ON IDX_FS.CUSIP = DATA_IS.CUSIP
)
LEFT JOIN DATA_SP ON IDX_FS.CUSIP = DATA_SP.CUSIP AND
( -- This is unmatched
(
(DATA_BS LEFT JOIN DATA_IS ON DATA_BS.CUSIP = DATA_IS.CUSIP AND DATA_BS.4DTYR = DATA_IS.4DTYR)
LEFT JOIN DATA_SP ON DATA_BS.CUSIP = DATA_SP.CUSIP AND DATA_BS.4DTYR = DATA_SP.4DTYR
)
LEFT JOIN DATA_Footnotes.4DTYR ON DATA_BS.CUSIP = DATA_Footnotes.CUSIP AND DATA_BS.4DTYR = DATA_Footnotes.4DTYR
-- A ) here perhaps?
答案 1 :(得分:0)
在FROM阶段,我们指定需要查询的表或表,以及表运算符 如果指定,则此阶段从左到右处理这些运算符。 Join(左/右)是表运算符,每个表运算符在一个或两个输入表上运行并返回一个输出表。表运算符的结果用作下一个表运算符的左输入 - 如果存在 - 并且作为下一个逻辑查询处理阶段的输入。 在您的查询中,我发现了两个问题:
我认为下面的伪可能会有所帮助:
select IDX_FS.CUSIP , DATA_BS.[4DTYR]
FROM
IDX_FS
LEFT JOIN DATA_BS
ON IDX_FS.CUSIP = DATA_BS.CUSIP
LEFT JOIN DATA_Footnotes
ON IDX_FS.CUSIP = DATA_Footnotes.CUSIP AND DATA_BS.CUSIP = DATA_Footnotes.CUSIP AND DATA_BS.[4DTYR] = DATA_Footnotes.[4DTYR]
LEFT JOIN DATA_IS
ON IDX_FS.CUSIP = DATA_IS.CUSIP AND DATA_BS.CUSIP = DATA_IS.CUSIP AND DATA_BS.[4DTYR] = DATA_IS.[4DTYR]
LEFT JOIN DATA_SP
ON IDX_FS.CUSIP = DATA_SP.CUSIP AND DATA_BS.CUSIP = DATA_SP.CUSIP AND DATA_BS.[4DTYR] = DATA_SP.[4DTYR]
-- LEFT JOIN DATA_Footnotes.[4DTYR] no need.
希望这有帮助!!!