[db] mysql group_concat

그룹화된 컬럼을 쭉 나열할 때 쓸 수 있는 함수이다

1
select team, group_concat(id) from user group by team;
1
2
3
4
A_team | 1,3,5
B_team | 2,4,6
C_team | 7,8,9
...

기본 구분자는 ,이고, 변경 가능하다

1
select team, group_concat(id separator '|') from user group by team;

앞뒤로 문자를 붙일수도 있다

1
2
3
4
5
-- 1__, 2__, 3__
select team, group_concat(id, '__') from user group by team;

-- __1__, __2__, __3__
select team, group_concat('__', id, '__') from user group by team;