我在mysql -mytable中有一个表。
列名:ResidenceAddress1
它的值如下:
sap3200@gmail.com,Rourkela
sap3212@gmail.com 2nd street,7 hils
2nd street, sap3212@gmail.com
我试过这种方式:
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?
答案 0 :(得分:1)
对于您的样本数据,这是一个解决方案:
public static final String MODULE = SomeClass.class.getName();
此答案基于您的电子邮件全部为MODULE
,而您的分隔符为空格。
<强> 编辑: 强>
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