0

我试图找出页面所有者(管理员)提出的问题中有多少评论。

tblQuestion:(问题表)

queID
queUserID
queCompanyID (the owner of the page where questions are asked)

tblReplies:(保存问题中的评论)

repQuestionID (queID = parent ID)
repUserID (the user ID who made the comment)

tblUsers:(存储用户的位置)

uID (user ID, autoincrement)
uCompanyID (if this id is the same as a company id, the user is admin of that page)

所以,我想知道公司所有者(使用 uCompanyID 回复帖子的父公司 ID - queCompanyID 的用户)发布了多少回复帖子。

我尝试这样做以获取页面管理员发布的帖子数量,但似乎不起作用:

SELECT COUNT(*) tblReplies.repID
FROM tblReplies
JOIN 
    tblQuestions ON tblQuestions.queID = tblReplies.repQuestionID
JOIN 
    tblUsers ON tblQuestions.queCompanyID = tblUsers.uCompanyID
WHERE tblQuestions.queID = 68 AND tblUsers.uCompanyID = 1

我真的希望那里有一个忍者可以帮助我,我已经花了几个小时但仍然一无所获。

谢谢!

4

3 回答 3

1

这应该可以工作(假设桌子userID上有一个。:tblUsers

SELECT 
    count(*), 
    tblReplies.repID
FROM 
    tblReplies, 
    tblQuestions, 
    tblUsers
WHERE
    tblQuestions.queID = tblReplies.repQuestionID AND
    tblQuestions.queCompanyID = tblUsers.uCompanyID AND
    tblUser.uID = tblReplies.repUserID AND
    tblUsers.uCompanyID = 1 AND 
    tblQuestions.queID = 68 

GROUP BY tblReplies.repID
于 2013-01-22T02:51:30.947 回答
0

这应该有效。

SELECT  count(*) as num_of_comments
FROM tblQuestion a
INNER JOIN tblReplies  b
    on a.queID = b.repQuestionID
INNER JOIN tblUsers c
    on b.queCompanyID = c.uCompanyID 
where a.queID = 68
    and c.uCompanyID = 1
于 2013-01-22T03:11:52.680 回答
0
SELECT COUNT(*) AS total 
FROM tblReplies 
WHERE repQuestionID =68 AND repUserID =1
于 2013-01-22T03:42:22.120 回答