SQL查询缺失运算符

时间:2017-09-05 14:23:44

标签: sql ms-access

我试图在myQuery中创建MainTable中每个Filename的出现次数。使用Access(是的,我知道)抱怨第一次加入中缺少运算符,如果我删除第二次加入就行。

我确实试图简化这一点以减少阅读。尽我所能,并不是一个缺少运营商的人。如果有更好的方法,或者你能发现问题,请告诉我。

    SELECT DISTINCT
      mainTable.Filename,
      mainTable.Link,
      otherTable.Field,
      qryC.Total           
    FROM mainTable
    LEFT JOIN otherTable
      ON mainTable.number = otherTable.position_nbr
    LEFT JOIN 
      (SELECT Filename, Count(*) As 
         Total FROM otherQuery
         GROUP BY Filename
       ) As qryC
      ON mainTable.Filename = qryC.Filename
    WHERE (((mainTable.Filename) IS NOT NULL
    OR (mainTable.Filename) <> ""));

1 个答案:

答案 0 :(得分:2)

MS Access需要FROM子句中的括号:

FROM (mainTable LEFT JOIN
      otherTable
      ON mainTable.number = otherTable.position_nbr
     ) LEFT JOIN 
     (SELECT Filename, Count(*) As Total
      FROM otherQuery
      GROUP BY Filename
     ) As qryC
     ON mainTable.Filename = qryC.Filename