Grouping dataset by concatenating text column with separator

Highlighted
lpdutra
Level 1
Grouping dataset by concatenating text column with separator
Jump to solution

Hello friends, I'm trying to group the dataset as shown below, but I'm not getting it. I think it's possible to use a custom key, but I don't know which SQL Expression to use. Has anyone ever had to do something like this?



Input:



order | product | value

100 | product A | 10.00

100 | product B | 5.00



Output:



order | concat_product | sum_value

100 | product A, product B | 15.00

 



Thank you,

Portes, Leo



[Edit]: Solution (Image)



order_test_dataset



compute_order_test_group



compute_order_test_group_2



0 Kudos
1 Solution

Accepted Solutions
Alex_Reutter Dataiker
Dataiker
Re: Grouping dataset by concatenating text column with separator
Jump to solution
I think STRING_AGG() is what you're looking for: https://www.postgresql.org/docs/current/static/functions-aggregate.html.

View solution in original post

0 Kudos
2 Replies
Alex_Reutter Dataiker
Dataiker
Re: Grouping dataset by concatenating text column with separator
Jump to solution
I think STRING_AGG() is what you're looking for: https://www.postgresql.org/docs/current/static/functions-aggregate.html.

View solution in original post

0 Kudos
lpdutra
Level 1
Re: Grouping dataset by concatenating text column with separator
Jump to solution
Hi Alex,

It worked with this function, but I had to use it in "Custom aggregations" and not in "Custom key" as I had thought.

string_agg("product", ',')

Thanks a lot for the help,
Leo
0 Kudos
Labels (2)