以下の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
Go to list of users who liked
Share on X(Twitter)
Share on Facebook
More than 5 years have passed since last update.
以下の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;
Register as a new user and use Qiita more conveniently
Go to list of users who liked