我按照他们的评论计数尝试select
个帖子
SELECT id,title
,(SELECT COUNT(*) FROM ci_comments WHERE (post_id = p.id)) AS comment_count
FROM ci_posts p
WHERE type='post' AND active=1
ORDER BY comment_count DESC , date_modified DESC LIMIT 6
这有效
但我需要过滤comment_count > 10
:
SELECT id,title
,(SELECT COUNT(*) FROM ci_comments WHERE (post_id = p.id)) AS comment_count
FROM ci_posts p
WHERE type='post' AND active=1 AND comment_count > 10
ORDER BY comment_count DESC , date_modified DESC LIMIT 6
结果:
Unknown column 'comment_count' in 'where clause'
那么解决方案是什么?
答案 0 :(得分:2)
尝试使用...查询查询结果
SELECT id,title
,(SELECT COUNT(*) FROM ci_comments WHERE (post_id = p.id)) AS comment_count
FROM ci_posts p
WHERE type='post' AND active=1
having comment_count >10
ORDER BY comment_count DESC , date_modified DESC LIMIT 6