Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过在MySQL中传递名称获取域名_Mysql - Fatal编程技术网

通过在MySQL中传递名称获取域名

通过在MySQL中传递名称获取域名,mysql,Mysql,我想通过传递域名来获取域名 考虑以下几点: CREATE TABLE `mails` ( `idmails` int(11) NOT NULL, `mails` varchar(45) DEFAULT NULL ); INSERT INTO mails VALUES(1,'harishsng@gmail.com'), (2,'harish.sn@m-tutor.com'),(3,'harishsn@yahoo.in'); 当我经过时 案例1:harishsng,结果应该是gmail,

我想通过传递域名来获取域名

考虑以下几点:

CREATE TABLE `mails` (
  `idmails` int(11) NOT NULL,
  `mails` varchar(45) DEFAULT NULL
);
INSERT INTO mails
VALUES(1,'harishsng@gmail.com'),
(2,'harish.sn@m-tutor.com'),(3,'harishsn@yahoo.in');
当我经过时 案例1:harishsng,结果应该是gmail, 案例2:harish.sn应该是m-tutor


如何在MySQL中实现这一点?

子字符串\u索引在这里很方便:

SELECT
    idmails,
    mails,
    SUBSTRING_INDEX(SUBSTRING_INDEX(mails, '@', -1), '.', 1) AS domain
FROM mails;


从bullet.mail中选择替换(替换(替换邮件,'harishsng','','@','','.com',''),其中邮件为'%harishsng%'

我想这就是你要找的。你可以用


这根本不是一个灵活的解决方案。请在回答中添加一些解释。只有代码的答案不受欢迎,也没有多大帮助。
select substring_index(substring_index(mails,'.com',1), '@', -1 )  from mails where email like 'harishsng%'
select mails,substring_index(substring_index(mails,'@',-1),'.',1)
from mails