如何从MySQL中的电子邮件地址值返回不同的域名? [英] How to return distinct domain names from email address values in MySQL?
本文介绍了如何从MySQL中的电子邮件地址值返回不同的域名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个MySQL表,其值如下:
I have a MySQL table with values like:
+--------------+
| user_email |
+--------------+
| ab@gmail.com |
| cd@gmail.com |
| ef@yahoo.com |
| gh@yahoo.com |
| ij@gmail.com |
| kl@other.net |
+--------------+
我需要从此电子邮件地址列表中返回唯一域名列表,例如:
I need to return a list of unique domain names from this list of email address, such as:
gmail.com,yahoo.com,other.net
到目前为止,我正在使用以下SQL语句来选择它:
So far, I am using the following SQL statement to select this:
SELECT SUBSTRING_INDEX(user_email,'@',-1)
但是,这只能解决我一半的问题-它正在返回域名.使用DISTINCT并不能解决问题.我想念什么?
However, this only solves half of my problem - it is returning domain names. Using DISTINCT did not do the trick. What am I missing?
仅供参考:它在LAMP堆栈上运行.谢谢!
FYI: This is running on a LAMP stack. Thanks!
推荐答案
只需使用分组依据
SELECT SUBSTRING_INDEX(user_email,'@',-1) as domain_name FROM user_email group by domain_name
这篇关于如何从MySQL中的电子邮件地址值返回不同的域名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文