sql - Concatenate multiple result rows of one column into one, group by another column -
this question has answer here:
i'm having table this
movie actor 1 2 3 b 4 i want name of movie , actors in movie, , want result in format this:
movie actorlist 1, 2, 3 how can it?
simpler aggregate function string_agg() (postgres 9.0 or later):
select movie, string_agg(actor, ', ') actor_list tbl group 1; the 1 in group 1 positional reference , shortcut group movie in case.
string_agg() expects data type text input. other types need cast explicitly (actor::text) - unless implicit cast text defined - case other character types (varchar, character, "char"), , other types.
Comments
Post a Comment