开发者

Combining result sets into array in SQL query

开发者 https://www.devze.com 2023-03-22 18:00 出处:网络
Let\'s say i have this table Col-ACol B 12 13 15 21 2开发者_JAVA百科2 28 And i want a query to return a result set built out of Col-A & an array of all Col-B value.

Let's say i have this table

Col-A     Col B 
  1         2
  1         3
  1         5
  2         1
  2     开发者_JAVA百科    2
  2         8

And i want a query to return a result set built out of Col-A & an array of all Col-B value.

Meaning a select that will return for this specific table:

Record1: 1,[2,3,5]

Record2: 2,[1,2,8]

Is this achievable?

Thanks.


Depending on your DBMS:

Oracle: SELECT col_a, WMSYS.WM_CONCAT(col_b) FROM my_table GROUP BY col_a;

SQLite: SELECT col_a, group_concat(col_b, ',') FROM my_table GROUP BY col_a;

0

精彩评论

暂无评论...
验证码 换一张
取 消