开发者

Need some help with SQL GroupBY

开发者 https://www.devze.com 2022-12-11 04:21 出处:网络
I have a two column table as follows: IDEmp开发者_高级运维 ID 11 12 13 14 22 26 210 31 35 48 52 56 I need something like this:

I have a two column table as follows:

ID    Emp开发者_高级运维 ID
1      1
1      2
1      3
1      4
2      2
2      6
2      10
3      1
3      5
4      8
5      2
5      6

I need something like this:

ID   Emp ID
1    1,2,3,4
2    2,6,10
3     1,5
4     8
5     2,6

Please help :)


Depends on your database. You need an aggregation function that concatenates the columns and separates them by columns. This, for example, works in sqlite:

select
    id,
    group_concat(emp_id)
from
    foo
group by id
0

精彩评论

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