-1

This question is modelled on How to get list of values in GROUP_BY clause? - which is a question, not applicable in BigQuery context.


If I have data like this in a table

id   data
--   ----
1    1
1    2
1    3
2    4
2    5
3    6
3    4

How do I get results like this in a query?

id   data
--   ----
1    1, 2, 3
2    4, 5
3    6, 4

where 1, 2, 3, 4, 5 and 6,4 are arrays.

zabop
  • 6,750
  • 3
  • 39
  • 84

1 Answers1

4

try this

SELECT
  id,
  ARRAY_AGG(data)
FROM
  table_name
GROUP BY
  id
nakaakist
  • 308
  • 4
  • 15