- postgres=# select * from book2;
- id | name | tag
- ----+------+-----
- 1 | java | aa
- 1 | java | bb
- 1 | java | cc
- 2 | C++ | dd
- 2 | C++ | ee
- (5 rows)
- postgres=# select name,string_agg(tag,',') from book2 group by name;
- name | string_agg
- ------+------------
- C++ | dd,ee
- java | aa,bb,cc
- (2 rows)
- postgres=# select * from book2;
- id | name | tag
- ----+------+-----
- 1 | java | aa
- 1 | java | bb
- 1 | java | cc
- 2 | C++ | dd
- 2 | C++ | ee
- (5 rows)