[英]MySql get the count of distinct domain
I have a users table like this. 我有一个这样的用户表。 Users may register from different emails ie
abc@xyz.com
and abc@uvw.com
. 用户可以从不同的电子邮件(即
abc@xyz.com
和abc@uvw.com
。 I need to get the count of different domains from the email. 我需要从电子邮件中获取不同域的数量。 My
users
table structure is 我的
users
表结构是
+----+------------------+------------------------+
| id | name | email |
+----+------------------+------------------------+
| 3 | shamsreza | shamsreza@abc.in |
| 4 | Kamal | kamalkumar@xyz.com |
| 6 | BIBHUDATTA SAHOO | admin@uvw.com |
| 7 | Bibhu Once Again | bibhuduttasahoo@xyz.in |
+----+------------------+------------------------+
I queried like this 我这样查询
select substring(email,LOCATE('@',email),LENGTH (email)) from users
It's giving me output as 它给我输出为
+---------------------------------------------------+
| substring(email,LOCATE('@',email),LENGTH (email)) |
+---------------------------------------------------+
| @uvw.com |
| @xyz.com |
| @xyz.com |
| @abc.in |
+---------------------------------------------------+
But here xyz.com
is repeated and i need the count of distinct domains. 但是这里
xyz.com
重复了,我需要计算不同的域。
for getting distinct results, you can use DISTINCT. 为了获得不同的结果,可以使用DISTINCT。
select distinct substring(email,LOCATE('@',email),LENGTH (email)) from users
Or in the case you want to count them: 或者,如果您要计算它们:
select count(distinct substring(email,LOCATE('@',email),LENGTH (email))) from users
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.