SQL:单个评论者留下的评论数

时间:2014-07-09 21:01:22

标签: mysql sql count

我正在尝试获取每个评论者(订阅者)留下的评论数量,并从最高到最低。

对于初学者来说,这是我去过的第一个链接:

SQL: How to get the count of each distinct value in a column?

类似的问题,除了在我的第一列中,值可能会重复。我看起来像这样。

email   | comment
--------------------
foo@bar | blah..
bar@bar | blah..
zob@bar | blah..
foo@bar | blah..
foo@bar | blah..
bar@bar | blah..

基本上我需要做的就是获得这样的输出

-foo@bar (3)
-bar@bar (2)
-zob@bar (1)

我知道这可能非常简单,我只是不经常使用SQL查询。

1 个答案:

答案 0 :(得分:4)

select 
  email, count(*)
from
  mytable
group by email
order by count(*) desc

这是fiddle

相关问题