开发者

getting the maxium count of comments in terms of users using mysql?

i have this 4 tables:

 posts{id,post,date}
    comment{id, user_id,post_id, comment, date}
    tag_post{tag_id,post_id}
    users{user_id, email,pwd,username}

i want to make this complex query, i want to get the maxiumum number of commenters(开发者_运维问答users) from a certain topic: i.e.

  select the most commeneters(count) on posts that have been tagged with tag_id=39
LIMIT 5

thanks :))


What about something like this :

select users.user_id, count(*) as nb_comments
from posts
    inner join tag_posts on tag_posts.post_id = posts.id
    inner join comment on comment.post_id = posts.id
    inner join users on users.user_id = comment.user_id
where tag_posts.tag_id = 39
group by users.user_id
order by count(*) desc
limit 5

It should get you the five users who commented the most on posts that have the tag 39.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜