3

如果您有电子邮件地址

you.late.you@asdf.com

you_late_you@asdf.com

如果使用 sql 代码有 2 个点/下划线,如何启用计数?

4

5 回答 5

6
select len('you.late.you@asdf.com') - len(replace('you.late.you@asdf.com', '.', ''))
于 2012-04-05T11:00:19.717 回答
1

这会给你想要的结果。

 DECLARE @str VARCHAR(1000)
SET @str = 'you.l_ate.you@as_df.com'
SELECT (LEN(@str)- LEN(REPLACE(@str ,'.' ,'')))+(LEN(@str)- LEN(REPLACE(@str ,'_' ,'')))

答案:5

于 2012-04-05T10:57:08.840 回答
1

我想他想数@之前没有点的字母:

declare @myEmail varchar(50)
set @myEmail = 'you.late.you@asdf.com'

declare @mySearch varchar(50)
set @mySearch = SUBSTRING (@myEmail,0 , PATINDEX( '%@%',@myEmail))
select (LEN(REPLACE(@mySearch, '.', '')))
于 2012-04-05T11:08:24.100 回答
0

如果要计算具有两个.or的行数_,可以执行以下操作:

select count(*) 
  from mytable 
 where left(email, charindex('@', email)) like '%[._]%[._]%'

leftandcharindex用于忽略域名(将有).

参考:LIKE(TSQL,SQL Server 2008)

于 2012-04-05T11:08:10.090 回答
0
select 
    length(substr('you.late.you@asdf.com',1,INSTR('you.late.you@asdf.com','@',1))) - 
    length(replace(substr('you.late.you@asdf.com',1,INSTR('you.late.you@asdf.com','@',1)), '.', '')) 
from dual
于 2013-06-19T15:07:36.217 回答