考虑到这样的电子邮件地址数据,我需要显示每个域中的用户数。:
+----------------------+
| 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中做到这一点?
答案 0 :(得分:3)
SELECT SUBSTRING_INDEX(email, '@', -1) AS `Email Acount`, COUNT(*) AS `Total Users`
FROM YourTable
GROUP BY `Email Acount`
MySQL SUBSTRING_INDEX
函数documentation