How to convert column values into separated with comma string in DB2

依然范特西╮ 提交于 2019-12-12 02:51:47

问题


I am unable to find DB2 query to make column values into one single value separating with comma.

Actual Table:

Table Name: Emp

Id Name
1 Test1
2 Test2
3 Test3

Expected Result:

Name
Test1,Test2,Test3

Cany some one suggest me the way to do it in DB2 or generic way in all databases ?

DB2 Version : 8.1 in windows environment

Many Thanks in advance!!!


回答1:


You don't mention what version of DB2 you are using. If you are on DB2 Linux/Unix/Windows, and are at version 9.7 or higher, then you can use the LISTAGG function:

SELECT LISTAGG(NAME, ',') FROM EMP



来源:https://stackoverflow.com/questions/25994896/how-to-convert-column-values-into-separated-with-comma-string-in-db2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!