好吧,我认识到,其实它更可能是我的逻辑的票错;)MySQL查询计数错误
因此,这里是我的查询:
SELECT
code.id AS codeid, code.title AS codetitle, code.summary AS codesummary, code.author AS codeauthor, code.date,
code_tags.*,
tags.*,
users.firstname AS authorname,
users.id AS authorid,
ratingItems.*, FORMAT((ratingItems.totalPoints/ratingItems.totalVotes), 1) AS rating,
GROUP_CONCAT(tags.tag SEPARATOR ', ') AS taggroup,
COUNT(comments.codeid) AS commentcount
FROM
code
join code_tags on code_tags.code_id = code.id
join tags on tags.id = code_tags.tag_id
join users on users.id = code.author
left join comments on comments.codeid = code.id
left join ratingItems on uniqueName = code.id
GROUP BY code_id
ORDER BY date DESC
LIMIT 0, 15
对不起有相当多的“膨胀的' 在那里面。我遇到的问题是commentcount
或(COUNT(comments.codeid) AS commentcount
) - 我想要统计代码提交的评论总数。以前,它工作正常,但我重新调整了我的MySQL语法,现在它停止工作:(
在数据库中只有2个code
提交有注释。正确返回的第一个结果表明它有超过0评论,但报告它作为具有commentcount
“2”的时候,其实它只有1
第二提交ALSO只有一个评论,不过,它告诉我,它有4个!
有人能告诉我我的逻辑有什么问题吗?
谢谢!
插孔
什么是code_id?我看到code.id和codeid,但我看不到Code_id的来源。 – Borealid 2010-07-07 09:07:34
我猜测,显示为2条评论的标签有2个标签,而显示为4条评论的标签有4个标签。是对的吗? – 2010-07-07 09:08:16