如何将此T-SQL查询转换为Access db接受?

时间:2014-04-08 00:28:02

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

我正在尝试转换查询,以便可以在Access DB上运行。出于某种原因,第二部分中的访问是抛出异常

  

查询表达式中的语法错误'(选择计数(p.id)FROM post p ...“

在这里,您可以看到SQL Server 2008上的所有内容都能正常运行:http://www.sqlfiddle.com/#!3/388fc/1

SELECT
   c.id,
   c.CategoryName,
   c.Description,
   (SELECT count(t.id)
    FROM topic t
    WHERE t.categoryId = c.id) AS NumberOfTopics,
   (SELECT count(p.id)
    FROM post p
    JOIN topic t ON p.topicId = t.id
    WHERE t.categoryId = c.id) AS NumberOfPosts,
   (SELECT top 1 max(p.createdOn) 
    FROM post p
    JOIN topic t ON p.topicId = t.id
    WHERE t.categoryId = c.id) AS LastPostDate,
   (SELECT top 1 createdby 
    FROM post p
    JOIN topic t ON p.topicId = t.id
    WHERE t.categoryId = c.id 
    ORDER BY p.createdon DESC) AS byperson
FROM 
   category c;

谢谢

1 个答案:

答案 0 :(得分:1)

访问要求您指明联接的类型:inner;剩下;或者是对的。它不会仅接受JOIN作为INNER JOIN的同义词。

所以让他们全部INNER JOIN并查看Access是否会出现任何其他投诉。