I have a users table like this. Users may register from different emails ie abc@xyz.com
and abc@uvw.com
. I need to get the count of different domains from the email. My users
table structure is
+----+------------------+------------------------+
| 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.
for getting distinct results, you can use 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.