到目前为止,这是我的查询:
SELECT
posts.title
, SUM(CASE comments.status WHEN 'approved' THEN 1 END) AS commentsCount
FROM posts
INNER JOIN comments
ON comments.postID = posts.id
WHERE
posts.status = ?
GROUP BY
posts.title
ORDER BY
commentsCount DESC
LIMIT 5
我需要让它在它得到时也检查comment.flagged
= 0 commentsCount
。我尝试CASE
在SUM()
调用中添加额外的 s,但这导致了致命错误。我怎样才能做到这一点?
谢谢!