Eu quero buscar o nome de domínio, passando o nome.
considere seguir,
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");
Quando eu passar Caso 1: harishsng, o resultado deve ser gmail, Caso 2: harish.sn deve ser m-tutor.
Como posso fazer isso no MySQL?
Respostas:
4 para resposta № 1SUBSTRING_INDEX
vem a calhar aqui:
SELECT
idmails,
mails,
SUBSTRING_INDEX(SUBSTRING_INDEX(mails, "@", -1), ".", 1) AS domain
FROM mails;
2 para resposta № 2
Eu acho que isto é o que você está procurando. Você pode usar substring_index
select substring_index(substring_index(mails,".com",1), "@", -1 ) from mails where email like "harishsng%"
0 para resposta № 3
SELECT substituir (substituir (substituir (mails, "harishsng", ""), "@", ""), ". Com", "") FROM bullet.mails onde e-mails como "% harishsng%";
0 para a resposta № 4
select mails,substring_index(substring_index(mails,"@",-1),".",1)
from mails