我有表HumanNames
输入
|HumanName |
|------------- |
|Kamil |
|Azer |
|John |
|Elmir |
|Kamal |
|Elmar |
|Orxan |
|Elnar |
我需要写查询,它会给出与其他名称相同的结果名称。 期望的输出是
|NamesWhichLikes |
|------------- |
|Kamil,Kamal |
|Elmir,Elmar,Elnar|
| |
答案 0 :(得分:9)
使用名称listagg
上的group by
和soundex
尝试此操作:
with your_table (HumanName) as (
select 'Kamil' from dual union all
select 'Azer' from dual union all
select 'John' from dual union all
select 'Elmir' from dual union all
select 'Kamal' from dual union all
select 'Elmar' from dual union all
select 'Orxan' from dual union all
select 'Elnar' from dual
)
------ Test data setup ends here ------
select
listagg(humanname,',') within group (order by humanname) nameswhichlikes
from your_table
group by soundex(humanname)
having count(*) > 1;
产地:
+---------------------------+
| NAMESWHICHLIKES |
+---------------------------+
| Elmar,Elmir,Elnar |
+---------------------------+
| Kamal,Kamil |
+---------------------------+
如果名称重复:
select
listagg(humanname,',') within group (order by humanname) nameswhichlikes
from (select distinct humanname from your_table)
group by soundex(humanname)
having count(*) > 1;