I have table here.
how to find all duplicate records, considering length(name)=3
? and append dups counter to the name as a suffix?
Below screenshot, Key 6 and 7
has characters length > 3 and when length(name)=3 then Jay is there two times so Key 6 and 7
name should have dups counter as suffix , after length(name)=3.
Below is expected for Key 6 and 7
I'm trying to use below query to get dups but it returns only dup data but not both Key 6 and 7
,
select *, left(name,3)||rank() over(partition by left(name,3) order by key) as expected_name
from (select key, name,rank() over(partition by left(name,3) order by key) as dups, tag
from label where length(name)>3
) a
where dups >1
Is there a way to get both dups rows so that i can append counter using rank function.