sql 查询有重复字符串的字段,这是为什么?

下表中,如何用sql查询出列1中有重复字符串的字段值,如“”张三三“”、“”李四四“”。备注:字段值随机,筛选出有重复字符串的字段记录就可以了,不需要统计次数等其他操作。


冉冉说
浏览 887回答 1
1回答

翻过高山走不出你

1:利用len函数 declare @a varchar(20) set @a='adfarghbaaf' select len(@a)- len(replace(@a,'a','')) 2:自定义一个函数 create function fn_str_times ( @str varchar(1000),--原子符串 @indexstr varchar(20)--查找的字符 ) returns int as begin declare @findlen int declare @times int set @findlen=LEN(@indexstr) set @times=0 while(charindex(@indexstr,@str))>0 BEGIN set @str=SUBSTRING(@str,CHARINDEX(@indexstr,@str)+@findlen,len(@str)) set @times=@times+1 end  return @times end select dbo.fn_str_times('adfarghbaaf','a')as 出现次数
打开App,查看更多内容
随时随地看视频慕课网APP