Count Email Address Domains
- by BRADINO
A quick tidbit I came up with today to count email addresses in a mysql database table grouping them by domain. So say for example you have a large list of subscribers and you want to see the breakdown of people who use Hotmail, Yahoo, Gmail, etc.
SELECT COUNT( SUBSTRING_INDEX( `email` , '@', -1 ) ) AS `count` ,
SUBSTRING_INDEX( `email` , '@', -1 ) AS `domain`
FROM `subscribers` WHERE `email` != ''
GROUP BY `domain`
ORDER BY `count` DESC
This sql statement assumes that the table is called 'subscribers' and the column containing the email addresses is 'email'. Change these two values to match your table name and email address column name.
mysql count email mysql count domain mysql split email mysql split domain