通过在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