每个用户的评论数 - mysql

时间:2015-07-09 11:48:29

标签: mysql

假设在Facebook上用户输入其状态,然后其他人对该状态发表评论。 所以,这样的情况会发生变化:

User 1 : My status 1
FB user 2: comment1
FB user 3: comment2
FB user 2: comment3
FB user 4: comment5

User 2 : My status 2
FB user 2: comment6
FB user 3: comment7

FB user 2: comment8

所有这些都存储在表status_table中,如ID,Status,FB_User,Comment

查找每个用户对特定状态所做的评论数量。

user2完成的评论

select count(comments) from status_table group by ID
Where status="%Good%" AND user=user2;

这是我最初的解决方案!!

问题是我认为这是对的,但面试官拒绝了它。

1 个答案:

答案 0 :(得分:0)

问题是每个用户而不是用户。所以可能是这样的:

select fb_user count(comments) from status_table 
  where status like '%[your particular status]%'
  group by fb_user;