The number of differences in a column

后端 未结 5 1128
情深已故
情深已故 2021-01-29 07:18

I would like to retrieve a column of how many differences in letters in each row. For instance

If you have a a value \"test\" and another row has a value \"testing \", t

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-29 07:54

    create table #temp
    (
    id int,
    value varchar(30),
    category int
    )
    
    insert into #temp
    select 1,'test',1
    union all
    select 2,'testing',1
    union all
    select 1,'Candy',2
    union all
    select 2,'Ca',2
    
    ;with cte
    as
    (
    select id,value,category,lead(value) over (partition by category order by id) as nxtvalue
    from #temp
    )
    select id,value,category,len(replace(nxtvalue,value,'')) as differences
    from cte
    

提交回复
热议问题