【发布时间】:2025-12-04 07:50:01
【问题描述】:
嗯,可以,但我不能查询;)
这是我的查询:
SELECT code.id AS codeid, code.title AS codetitle, code.summary AS codesummary, code.author AS codeauthor, code.date, code.challengeid, ratingItems.*, FORMAT((ratingItems.totalPoints / ratingItems.totalVotes), 1) AS rating, code_tags.*, tags.*, users.firstname AS authorname, users.id AS authorid, GROUP_CONCAT(tags.tag SEPARATOR ', ') AS taggroup,
COUNT(DISTINCT 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
WHERE `code`.`approved` = 1
GROUP BY code_id
ORDER BY date desc
LIMIT 15
重要的一行是第二行——我已经缩进的那一行。我要求它计算特定帖子上的 cmets 数量,但它没有返回正确的数字。例如,带有两个 cmets 的东西将返回“1”。两个不同作者的 8 cmets 仍然会返回“1”...
有什么想法吗?
谢谢!
杰克
编辑:忘了说。当我删除 DISTINCT 部分时,来自两位作者的 8 cmets 返回“28”。抱歉,我不是 MySQL 专家,我真的不明白为什么它会返回 :(
【问题讨论】: