问题
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