另一个表上的访问计数不起作用
我有一个博客系统的 Posts 表和 PostComments 表。我想按评论计数对帖子进行计数和排序,但我的查询不起作用。:
SELECT Posts.PostID, Posts.DateCreated, Posts.Title, Posts.Description,
Posts.Hits, (SELECT Count(CommentID) FROM PostComments WHERE
PostComments.PostID=Posts.PostID AND PostComments.IsApproved=True) AS
CommentCount FROM Posts ORDER BY Posts.PostID DESC;
我也尝试过:
SELECT Posts.PostID, Posts.DateCreated, Posts.Title, Posts.Description,
Posts.Hits, Count([CommentID]) AS CommentCount FROM Posts INNER JOIN PostComments
ON Posts.PostID = PostComments.PostID;
但出现错误“您试图执行不包含指定表达式“PostID”的查询作为聚合函数的一部分。”
I have a Posts table and PostComments table of a blog system. I want to count and sort the posts by comment count but my query won't work.:
SELECT Posts.PostID, Posts.DateCreated, Posts.Title, Posts.Description,
Posts.Hits, (SELECT Count(CommentID) FROM PostComments WHERE
PostComments.PostID=Posts.PostID AND PostComments.IsApproved=True) AS
CommentCount FROM Posts ORDER BY Posts.PostID DESC;
I also tried:
SELECT Posts.PostID, Posts.DateCreated, Posts.Title, Posts.Description,
Posts.Hits, Count([CommentID]) AS CommentCount FROM Posts INNER JOIN PostComments
ON Posts.PostID = PostComments.PostID;
But have error "You tried to execute a query that does not include specified expression 'PostID' as a part of an aggregate function."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我是一个十足的 Access 菜鸟,但请尝试按非聚合列进行分组的第二个。
也许您必须在 MS-Access 中将
JOIN
行放入大括号中。I'm a complete Access noob, but try the second one with a grouping by the non-aggregated columns.
Maybe you have to put the
JOIN
row into braces in MS-Access.尝试
Try