如果是oracle 数据库的话可以这样,至于效率的话......,哥 你懂的
select 列2,ltrim(max(sys_connect_by_path(列3,',')),',') 列3
from (
select 列2,列3,列2||rn child,decode(rn,1,null,列2||(rn-1)) parent
from (
select 列2,列3,row_number() over( partition by 列2 order by 列3) rn
from (
select 1 ,'中国' 列2,'a' 列3
from dual
union
select 2 ,'usa' 列2,'b' 列3
from dual
union
select 5 ,'usa' 列2,'d' 列3
from dual
union
select 3 ,'英国' 列2,'c' 列3
from dual
union
select 4 ,'中国' 列2,'e' 列3
from dual
) a
) b
) c
start with parent is null
connect by prior child = parent
group by 列2