Reputation: 19
Given email addresss data like this, I need to display the number of users in each domain.:
+----------------------+
| email |
+----------------------+
| [email protected] |
| [email protected] |
| [email protected] |
| [email protected] |
| [email protected] |
| [email protected] |
| [email protected] |
| [email protected] |
| [email protected] |
| [email protected] |
+----------------------+
I want output like this:
+----------------------+-------------+
| Email Acount | Total Users |
+----------------------+-------------+
| gmail.com | 3 |
| lycos.com | 1 |
| yahoo.com | 6 |
+----------------------+-------------+
How should I do that in MySQL?
Upvotes: 1
Views: 184
Reputation: 780929
SELECT SUBSTRING_INDEX(email, '@', -1) AS `Email Acount`, COUNT(*) AS `Total Users`
FROM YourTable
GROUP BY `Email Acount`
MySQL SUBSTRING_INDEX
function documentation
Upvotes: 3