17,377
社区成员
发帖
与我相关
我的任务
分享
--测试数据
create table test(a int,b varchar2(100),c varchar2(100));
insert into test
select 1,'XXX','01' from dual union all
select 2,'YYY','01' from dual union all
select 3,'KKK','02' from dual union all
select 4,'III','02' from dual;
--执行查询
select c,replace(substr(max(sys_connect_by_path(b, '|')), 2),'|','') b
from (select b, c, row_number() over(partition by c order by 1) rn
from test)
start with rn = 1
connect by rn - 1 = prior rn and c = prior c
group by c;
--查询结果
c b
01 XXXYYY
02 KKKIII