繁体   English   中英

MS Access SQL查询语法错误

[英]Ms Access SQL Query syntax error

以下是我的MS Access SQL查询

    SELECT '2012/8'      AS [Period],
       yearmonth.[Monthno (PS)] AS monthno,
       [assignment_2012].[cluster code] AS cluster,
       'Transfer out' AS Remark,
       -1*Count(*)      AS [number],
       '5'           AS [sorting]
FROM  [assignment_2012] 
INNER JOIN namesort ON [assignment_2012].post = namesort.post 
INNER JOIN yearmonth ON [assignment_2012].[year month]=yearmonth.[Year Month (HM)] 
INNER JOIN
       (SELECT empid
                     FROM   (SELECT empid,
                                    [cluster],
                                    Count(*) AS [empid no]
                             FROM   (SELECT [ID] as empid,
                                            [Cluster Code] as cluster 
                                     FROM   [assignment_2012]
                                            INNER JOIN yearmonth
                                                    ON [assignment_2012].[year month]
                                                       =
                                                       yearmonth.[Year Month (HM)]
                                     WHERE  yearmonth.[Monthno (PS)] = 243
                                            AND [assignment_2012].hc_adj = 1
                                            AND [assignment_2012].term <> 'Temporary'
                                     UNION
                                     SELECT empid,
                                            [cluster]
                                     FROM   [2012]
                                     WHERE  monthno = 244
                                            AND [2012].term <> 'Temporary'
                                            AND ( div <> 'XXX'
                                                   OR div IS NULL )
                                            AND hc = 1)
                             GROUP  BY [empid],
                                       [cluster]
                             HAVING Count(*) = 1)
                     GROUP  BY empid
                     HAVING Count(*) > 1) As Emps
ON [assignment_2012]].EmpID = Emps.EmpID
WHERE  yearmonth.[Monthno (PS)] = 243
       AND [assignment_2012].hc_adj = 1
       AND yearmonth.[Monthno (PS)] BETWEEN namesort.monthno_start AND namesort.monthno_end
       AND [assignment_2012].term <> 'Temporary'
GROUP  BY yearmonth.[Monthno (PS)], [assignment_2012].[cluster code]

当我运行查询时,它提示消息“查询表达式'[assignment_2012] .post = namesort.post内部联接........中的语法错误(缺少运算符)”

我发现如果在sql语句中包含“ INNER JOIN yearmonth ON [assignment_2012]。[year month] = yearmonth。[Year Month(HM)]”,则会返回错误。

我已经修改了Yearmonth表的INNER JOIN语句,现在可以使用了。

SELECT '2012/8' AS Period, YearMonth.[Monthno (PS)], assignment_2012.[cluster code] AS cluster, 'Transfer out' AS Remark, -1*Count(*) AS [number], '5' AS sorting
FROM YearMonth INNER JOIN ((assignment_2012 INNER JOIN namesort ON assignment_2012.post = namesort.post) INNER JOIN (SELECT empid
                     FROM   (SELECT empid,
                                    [cluster],
                                    Count(*) AS [empid no]
                             FROM   (SELECT [HKID] as empid,
                                            [Cluster Code] as cluster 
                                     FROM   [assignment_2012]
                                            INNER JOIN yearmonth
                                                    ON [assignment_2012].[year month]
                                                       =
                                                       yearmonth.[Year Month (HM)]
                                     WHERE  yearmonth.[Monthno (PS)] = 243
                                            AND [assignment_2012].hc_adj = 1
                                            AND [assignment_2012].term <> 'Temporary'
                                     UNION
                                     SELECT empid,
                                            [cluster]
                                     FROM   [2012]
                                     WHERE  monthno = 244
                                            AND [2012].term <> 'Temporary'
                                            AND ( div <> 'XXX'
                                                   OR div IS NULL )
                                            AND hc = 1)
                             GROUP  BY [empid],
                                       [cluster]
                             HAVING Count(*) = 1)
                     GROUP  BY empid
                     HAVING Count(*) > 1)  AS Emps ON assignment_2012.ID = Emps.EmpID) ON YearMonth.[Year Month (HM)] = assignment_2012.[Year Month]
WHERE (((assignment_2012.hc_adj)=1) AND ((assignment_2012.term)<>'Temporary'))
GROUP BY YearMonth.[Monthno (PS)], assignment_2012.[cluster code];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM