Count the number of entries for a given column
Its probably an easy question but hard for me: I have the following table (columns)
[id, email_from, email_to, email_subject, timestamp]
id and timestamp are numeric and the rest are text fields
for that example:
[1, john@mail.com, patrick@mail.com, ...]
[2, john@mail.com, carol@mail.com, ...]
[3, john@mail.com, john@mail.com, ...]
[4, john@mail.com, jimmy@mail.com, ...]
[5, jimmy@mail.com, carol@mail.com, ...]
[6, jimmy@mail.com, john@mail.com, ...]
[8, jimmy@mail.com, carol@mail.com, ...]
[9, carol@mail.com, patrick@mail.com, ...]
I'd like to retrieve the number of mails sent by each user. The result should be like:
[john@mail.com开发者_开发知识库,4]
[jimmy@mail.com,3]
[carol@mail.com,1]
Thanks
select email_from, count(*) from yourtable group by email_from
and possibly adding an
order by count(*) desc
if you want it ordered by most to least emails sent
SELECT email_from, COUNT(email_from) AS 'Count' FROM table_name GROUP BY email_from
精彩评论