문제

I have a table with rows of data and need to create a comma delimited string for all the rows for a column. Can this be achieved just using the the SELECT statement in SQLite or I have to get the data into Cursor and build the string by iterating through it?

For Example:

UserId
1df4181d-6c52-4aa3-926f-2dacb0a68c70
1df4181d-6c52-4aa3-926f-2dacb0a68c71
1df4181d-6c52-4aa3-926f-2dacb0a68c72
1df4181d-6c52-4aa3-926f-2dacb0a68c73
1df4181d-6c52-4aa3-926f-2dacb0a68c74
1df4181d-6c52-4aa3-926f-2dacb0a68c75

into

1df4181d-6c52-4aa3-926f-2dacb0a68c70,1df4181d-6c52-4aa3-926f-2dacb0a68c71,1df4181d-6c52-4aa3-926f-2dacb0a68c72,1df4181d-6c52-4aa3-926f-2dacb0a68c73,1df4181d-6c52-4aa3-926f-2dacb0a68c74,1df4181d-6c52-4aa3-926f-2dacb0a68c75

Any suggestions would be greatly appreciated.

도움이 되었습니까?

해결책

You can use GROUP_CONCAT():

select group_concat(yourColumn, ',')
from yourtable

See SQL Fiddle with Demo

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top