我在mysql -mytable中有一个表。
列名称:ResidenceAddress1
它具有这样的值:
[email protected],Rourkela
[email protected] 2nd street,7 hils
2nd street, [email protected]
我已经尝试过这种方式:
select (case when substring_index(Residence_Address1, ' ', 1) like '%@%'
then substring_index(Residence_Address1, ' ', 1)
else substring_index(Residence_Address1, ' ', -1)
end) as email, Residence_Address1
from mytable
where Residence_Address1 like '%gmail%' and Email_Personal1=""
但是它不仅给我提供电子邮件ID。如何仅从多个单词中获取电子邮件ID?
最佳答案
对于您的示例数据,这是一个解决方案:
select
concat(trim(substring_index(substring_index(ResidenceAddress1, '@', '1'), ' ', -1)), '@gmail.com') as mail
,ResidenceAddress1
from mytable
该答案基于您的电子邮件全为
gmail.com
,分隔符为空格。编辑:
substring_index(ResidenceAddress1, '@', '1')
将为您提供:sap3200
sap3212
2nd street, sap3212
然后
substring_index('sap3200', ' ', -1) => sap3200
substring_index('sap3212', ' ', -1) => sap3212
substring_index('2nd street, sap3212', ' ', -1) => sap3212