Reputation: 3913
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, [email protected], [email protected], ...]
[2, [email protected], [email protected], ...]
[3, [email protected], [email protected], ...]
[4, [email protected], [email protected], ...]
[5, [email protected], [email protected], ...]
[6, [email protected], [email protected], ...]
[8, [email protected], [email protected], ...]
[9, [email protected], [email protected], ...]
I'd like to retrieve the number of mails sent by each user. The result should be like:
[[email protected],4]
[[email protected],3]
[[email protected],1]
Thanks
Upvotes: 0
Views: 70
Reputation: 1140
SELECT email_from, COUNT(email_from) AS 'Count' FROM table_name GROUP BY email_from
Upvotes: 0
Reputation: 23796
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
Upvotes: 2