快捷导航

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

下表中,如何用sql查询出列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 intasbegindeclare @findlen intdeclare @times intset @findlen=LEN(@indexstr)set @times=0while(charindex(@indexstr,@str))>0BEGINset @str=SUBSTRING(@str,CHARINDEX(@indexstr,@str)+@findlen,len(@str))set @times=@times+1end return @timesendselect dbo.fn_str_times('adfarghbaaf','a')as 出现次数
回复

使用道具 举报

可能感兴趣的问答

发新帖
  • 微信访问
  • 手机APP