Oracle 写法
with tmp as (select 'CCDD' as id from dualunion select 'AABB' from dual),tmp1 as (select 'CC' as id,'张三' as NAME from dualunion allselect 'DD' as id,'李四' as NAME from dual)selectt.id,listagg(t1.name,'')within group(order by t1.name)from tmp tleft join tmp1 t1on t.id like '%'||t1.id||'%'group by t.id
GP写法
with tmp as (select 'CCDD' as idunion select 'AABB'),tmp1 as (select 'CC' as id,'张三' as NAMEunion allselect 'DD' as id,'李四' as NAME)selectt.id,string_agg(t1.name,'') from tmp tleft join tmp1 t1on t.id like '%'||t1.id||'%'group by t.id