如何在sql server中判斷某欄位中重複出現某字元多次

時間 2021-10-14 22:25:42

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

asbegin

declare @findlen int

declare @times int

set @findlen=len(@indexstr)set @times=0

while(charindex(@indexstr,@str))>0begin

set @str=substring(@str,charindex(@indexstr,@str)+@findlen,len(@str))

set @times=@times+1

endreturn @times

endselect dbo.fn_str_times('adfarghbaaf','a')as 出現次數

2樓:

declare @s nvarchar(200)set @s='fire safety;fire sprinklers;inspection;installation;maintenance'

select

number

from master.dbo.spt_values as awhere number>0 and type='p' and substring(@s,number,1)=';'

/*12

2839

52*/

sql統計某欄位中資料重複出現的次數

3樓:玩轉資料處理

declare @tt table (name varchar(100))

insert into @tt values ('張三')

insert into @tt values ('李四,張三')

insert into @tt values ('王五 趙六')

insert into @tt values ('趙六')

insert into @tt values ('李四')

insert into @tt values ('王五,趙六  李四')

insert into @tt values ('趙六,王五')

declare @line varchar(max)

select @line = stuff(( select ',' + name from @tt for xml path('')) , 1, 1, '')

select @line = replace(@line,' ',',')

print(@line)

sql seever怎麼查出某個欄位重複出現兩次以上的資料

4樓:匿名使用者

select * from 表 where 欄位 in( select 欄位 from 表 ...

怎麼利用sql語句查詢資料庫中具體某個欄位的重複行

sql怎麼統計在某個欄位中某個值出現的總次數

5樓:匿名使用者

select sum(case when value='sh' then 1 esle 0 end) sh, sum(case when value='bj' then 1 esle 0 end) bj,name

from table

group by name

6樓:匿名使用者

左轉數學吧——from here』s to change 8❎

sql server 2019如何在已經建立的表中把已有的某

1 create table test tab 2 id int,3 name varchar 10 4 age int,5 val varchar 10 6 7 go 1 alter table test tab 2 add constraint pk test tab primary key i...

怎麼判斷sql server中某欄位含空格

小丁創業 方法和詳細的操作步驟如下 1 第一步,需要使用建立表sql語句來建立資料庫表t user info,見下圖,轉到下面的步驟。2 第二步,完成上述步驟後,將資料插入資料庫表,然後根據insert sql語句insert into執行資料,見下圖,轉到下面的步驟。3 第三步,完成上述步驟後,從...

如何在CAN驅動中新增接收丟幀判斷

can匯流排控制器用於實現can協議和基礎資料鏈路層,以及用於產生一個can幀傳送的二進位制流模式,位在這個過程中餡,新增crc校驗,應答檢測操作 接收的二進位制碼流被解析和接收收發器在此過程相比,位元填充來執行crc校驗操作。此外,需要衝突的判斷,錯誤處理等多項任務。can收發器 有時也被稱為驅動...