给定这样的电子邮件地址数据,我需要显示每个域中的用户数
+----------------------+
| email |
+----------------------+
| richardg07@gmail.com |
| anolimous@yahoo.com |
| binnerts@yahoo.com |
| retsel@yahoo.com |
| Val@gmail.com |
| mayaman@yahoo.com |
| marylaine@yahoo.com |
| richardg07@gmail.com |
| shaider07@lycos.com |
| yayabelles@yahoo.com |
+----------------------+
我想要这样的输出:
+----------------------+-------------+
| Email Acount | Total Users |
+----------------------+-------------+
| gmail.com | 3 |
| lycos.com | 1 |
| yahoo.com | 6 |
+----------------------+-------------+
在MySQL中我应该怎么做?
最佳答案
SELECT SUBSTRING_INDEX(email, '@', -1) AS `Email Acount`, COUNT(*) AS `Total Users`
FROM YourTable
GROUP BY `Email Acount`
MySQL
SUBSTRING_INDEX
函数documentationDEMO
关于mysql - 如何计算按域分组的电子邮件地址?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24752286/