我想通过传递域名来获取域名。
考虑一下,
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-家教。
我如何在MySQL中做到这一点?
发布于 2018-04-27 04:41:16
SUBSTRING_INDEX在这里派上用场:
SELECT
idmails,
mails,
SUBSTRING_INDEX(SUBSTRING_INDEX(mails, '@', -1), '.', 1) AS domain
FROM mails;

演示
发布于 2018-04-27 04:50:33
我想这就是你要找的。您可以使用索引
select substring_index(substring_index(mails,'.com',1), '@', -1 ) from mails where email like 'harishsng%'发布于 2018-04-27 04:41:39
从bullet.mails中选择替换(邮件、'harishsng‘、'')、'@’、‘..com’、‘),其中像’%harishsng%‘这样的邮件;
https://stackoverflow.com/questions/50055309
复制相似问题