我正在尝试获取每个评论者(订阅者)留下的评论数量,并按从高到低的顺序排列。
对于初学者,这是我访问的第一个链接:
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 查询。
最佳答案
select
email, count(*)
from
mytable
group by email
order by count(*) desc
这是一个 fiddle
关于mysql - SQL:单个评论者留下的评论数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24663744/