卡在 SQL 查询上来计算行数
SELECT
COUNT(*) AS TotalUserVotes
FROM tblArticleVotes AS v
INNER JOIN tblArticles AS a
ON v.ArticleID = a.ID
AND a.AuthorID = 13405
它始终返回 0。我有一个表 tblArticles
,其中包含 AuthorID
和 ID
(文章的主键)。
然后我有一个文章投票表,其中有一个 articleID
列。
给定用户13405
,我需要找出他们在所有文章中拥有多少票!
需要确认的是,当前 tblArticleVotes
中有一条文章 ID 为 5
的记录。文章 ID 5 的作者 ID 为 13405。
SELECT
COUNT(*) AS TotalUserVotes
FROM tblArticleVotes AS v
INNER JOIN tblArticles AS a
ON v.ArticleID = a.ID
AND a.AuthorID = 13405
This always returns 0. I have a table tblArticles
which has an AuthorID
and ID
(primary key for article).
I then have an article votes table, with an articleID
column.
Given user 13405
I need to find out how many votes they have across all of their articles!
Just to confirm, there is currently one record in tblArticleVotes
which has the articleID of 5
. Article ID 5 has the author ID of 13405.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
嗯... JOIN 中的 AuthorID 看起来很奇怪...也许这样效果更好?
Hmmm... the AuthorID in the JOIN looks odd... maybe this works better?
尝试将“AND”更改为“WHERE”:
HTH
Try changing the "AND" to "WHERE":
HTH
你的查询没有任何问题。要解决此问题,请分解查询。
There is nothing wrong with your query. To trouble shoot this break the query up.
试试这个:
try this instead: