メールアドレスをお持ちの方
you.late.you@asdf.com
you_late_you@asdf.com
SQLコードを使用して2つのドット/アンダースコアがある場合、どのように数えることができますか?
メールアドレスをお持ちの方
you.late.you@asdf.com
you_late_you@asdf.com
SQLコードを使用して2つのドット/アンダースコアがある場合、どのように数えることができますか?
select len('you.late.you@asdf.com') - len(replace('you.late.you@asdf.com', '.', ''))
@ の前にドットを付けずに文字を数えたいと思っているようです。
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, '.', '')))
これにより、目的の結果が得られます。
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
.
またはが 2 つある行の数を数えたい場合_
は、次のようにします。
select count(*)
from mytable
where left(email, charindex('@', email)) like '%[._]%[._]%'
left
とはcharindex
、ドメイン名を無視するために使用されます (これには が付きます.
)。
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