简体   繁体   English

如何转换此T-SQL查询以被Access db接受?

[英]How to convert this T-SQL query to be accepted by Access db?

I am trying to convert a query so it can be run on Access DB. 我正在尝试转换查询,以便可以在Access DB上运行它。 For some reason access in the second part is throwing the exception 由于某些原因,第二部分中的访问将引发异常

Syntax error in query expression '(Select count(p.id) FROM post p..." 查询表达式'((从后...中选择count(p.id)...时出现语法错误...“

Here you can see that everything works perfectly on SQL Server 2008: http://www.sqlfiddle.com/#!3/388fc/1 在这里,您可以看到所有内容都可以在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;

Thank you 谢谢

Access requires that you indicate the type of join: inner; 访问要求您指出联接的类型:internal; left; 剩下; or right. 或对。 It will not accept just JOIN as a synonym for INNER JOIN . 它不会只接受JOIN作为INNER JOIN的同义词。

So make all of them INNER JOIN and see whether Access surfaces any other complaints. 因此,使所有这些成员都成为INNER JOIN然后查看Access是否会出现其他任何投诉。

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

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