Mysql:如何通过PATTERN/LIKE语句生成计数表?非常狡猾
为了简化,我有一个注册用户数据库,我想计算每个电子邮件域名有多少封电子邮件(注意我不知道所有域名) 比如说,, 用户表-Mysql:如何通过PATTERN/LIKE语句生成计数表?非常狡猾,mysql,Mysql,为了简化,我有一个注册用户数据库,我想计算每个电子邮件域名有多少封电子邮件(注意我不知道所有域名) 比如说,, 用户表- id | email ------------------ 1 | test@hotmail.com 2 | test@somesite.aaa<--unknown to me 3 | test@unknownsite.aaa<--unknown to me 4 | test@hotmail.com 5 | te
id | email
------------------
1 | test@hotmail.com
2 | test@somesite.aaa<--unknown to me
3 | test@unknownsite.aaa<--unknown to me
4 | test@hotmail.com
5 | test@somesite.aaa<--unknown to me
6 | test@yahoo.com
7 | test@yahoo.com
8 | test@hotmail.com
我再次强调,我不知道unknownsite.aaa,也不能在声明中提及,因为我不知道,希望我清楚。
所以本质上我想统计一下我的网站用户使用什么作为电子邮件主机网站。
但正如我所说,我将重复第三次,我不知道存在的每一个邮件主机。
我将对此进行更多的调查,我有一种感觉,这是mysql无法处理的
编辑:
我提出了以下解决方案,但似乎有点多余,我讨厌:p
select substring_index(`email`,'@',-1),count(*) as count from users group by substring_index(`email`,'@',-1) order by count ASC;
在mysql中使用RLIKE或REGEXP
在mysql中使用RLIKE或REGEXP 在电视上看
请参见。在本例中,regexp是一个巨大的杀伤力。在本例中,regexp是一个巨大的杀伤力。
select substring_index(`email`,'@',-1),count(*) as count from users group by substring_index(`email`,'@',-1) order by count ASC;
SELECT SUBSTRING_INDEX(email, '@', -1) AS suffix, COUNT(*) AS count
FROM users
GROUP BY suffix