5
votes

I have a table in BigQuery:

|c1|c2|c3|
----------
|a1|'b'|c1|
----------
|a1|'a'|c2|
----------

and I want to group by c1 and array_agg c2 and have a table like below:

 c1| c2
--------
 a1|'ab'

which concatenate the c2 column and save the alphabetic order. can someone help me with this?

1
What have you tried? Your question pretty much describes the query. - Gordon Linoff

1 Answers

0
votes

try the following. you can use order by inside string_agg. here is the documentation.

select
    c1,
    string_agg(c2 order by c2) as c2
from yourTable
group by
    c1