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

How to create list from long data in bigquery?

Hi I have a table like so

orderId productId
1 23
1 24
1 27
2 25
2 26
3 27

and want to transform it into

orderId productIds
1 23,24,27
2 25,26
3 27

How do I achieve this?

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

>Solution :

Use STRING_AGG:

SELECT orderId, STRING_AGG(productId ORDER BY productId) AS productIds
FROM yourTable
ORDER BY orderId;
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