LoginSignup
9
8

More than 5 years have passed since last update.

Postgres で group by + array_to_stringをする。

Posted at

以下のtableを

ID NAME
1 AAA
1 BBB
2 CCC
2 DDD
2 AAA
3 EEE

以下のようにするには。

ID NAME
1 AAA,BBB,CCC
2 CCC,DDD,AAA
3 EEE
SELECT ID, string_agg(NAME, ',')
FROM table
GROUP BY ID;
  • Postgresのバージョンは9.0
9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8