378 发表于 2016-11-16 08:38:37

DB2多行转一行【XML方式】

分组然后合并,然后去除XML标签
SELECT replace(replace(replace(xml2clob(xmlagg(xmlelement(name A, 【字段】))),'</A><A>', '【分隔符】'),'</A>',''),'<A>','')   
from 【表】
group by 【分组字段】
  

  如:
  SELECT replace(replace(replace(xml2clob(xmlagg(xmlelement(name A, nounid))),'</A><A>', ','),'</A>',''),'<A>','')

from SYS_NOUN

group by nounsuper


这种方式运行速度很快。
页: [1]
查看完整版本: DB2多行转一行【XML方式】