给定这样的电子邮件地址数据,我需要显示每个域中的用户数

+----------------------+
| 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`

MySQLSUBSTRING_INDEX函数documentation
DEMO

关于mysql - 如何计算按域分组的电子邮件地址?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24752286/

10-14 12:59
查看更多