2013-08-20 41 views
0

我有以下结果集:的毗连SQL结果行

ID | mark | cost | comment 
1  yel  45  array 
3  yel  45  tack 

现在我想只有1列,如:

ID | mark | cost | comment 
1  yel  45  array tack 

如果标记和成本是相同的。

关于如何做到这一点的任何想法?

+1

请看看这个:http://stackoverflow.com/questions/194852/concatenate-many-rows-into-a-single-text-string – hogni89

+1

的[从查询创建delimitted字符串可能重复在DB2中](http://stackoverflow.com/questions/3728010/create-a-delimitted-string-from-a-query-in-db2) – GarethD

+0

从版本9.7.4开始,DB2支持'LISTAGG()'字符串聚合功能。你可以[看](http://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.sql.ref.doc%2Fdoc%2Fr0058709.html )在它。 –

回答

1
select min(id), 
     mark, 
     cost, 
     substr(xmlserialize(xmlagg(xmltext(concat(' ', comment))) as varchar(1024)), 3) 
    from t1 
group by mark, 
      cost;