Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Group multiple rows values into a single row

I want to merge multiple row values for same id into a single row value separated by commas

How can do this in Athena?

This is the data:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

This is the expected result:

[After]()

I appreciate your help and ideas. Thanks in advance.

>Solution :

You can use array_agg aggregate function:

-- sample data
with dataset(id, interest) as(
    values (1,  'Math'),
        (1,  'Poetry'),
        (1,  'Art'),
        (2,  'Math'),
        (2,  'Other')
)

-- query
select id, array_agg(interest) interest
from dataset
group by id

Output:

id interest
1 [Math, Poetry, Art]
2 [Math, Other]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading