'How to list column elements separated by comma
I have a table which contains the locations, the actors and activities complete by actors. Please see the example on the below image. enter image description here
For each location (first column) and each activity, list all the actors who are working in on that activity separated by coma. I would like to to have an output like this enter image description here
I was doing that in SQL Server, but I am now migrating to PostgreSQL.
Thanks for the advice. I used STRING_AGG() function, but need more guidance to eliminate the duplication and loop for all value. Below is my query
SELECT
L.location_name,
STRING_AGG (
L.actor || ' ',
','
ORDER BY
L.actor
) activity_1
FROM
location_actor_activity L
WHERE activity = 'Activity_A'
GROUP BY L.location_name;
Which is giving result with duplication of actors enter image description here
Thank you
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|